Class: Queries::Tag::Filter
- Inherits:
-
Object
- Object
- Queries::Tag::Filter
- Defined in:
- lib/queries/tag/filter.rb
Overview
!! does not inherit from base query
Instance Attribute Summary collapse
-
#keyword_id ⇒ Object
Array, Integer.
-
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here.
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_keyword_id ⇒ Arel::Node?
- #table ⇒ Arel::Table
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
19 20 21 22 |
# File 'lib/queries/tag/filter.rb', line 19 def initialize(params) @keyword_id = [params[:keyword_id]].flatten.compact @options = params end |
Instance Attribute Details
#keyword_id ⇒ Object
Array, Integer
16 17 18 |
# File 'lib/queries/tag/filter.rb', line 16 def keyword_id @keyword_id end |
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here
11 12 13 |
# File 'lib/queries/tag/filter.rb', line 11 def @options end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
44 45 46 47 48 49 50 |
# File 'lib/queries/tag/filter.rb', line 44 def all if a = and_clauses ::Tag.where(and_clauses).distinct else ::Tag.all end end |
#and_clauses ⇒ ActiveRecord::Relation
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/queries/tag/filter.rb', line 25 def and_clauses clauses = [ ::Queries::Annotator.annotator_params(, ::Tag), matching_keyword_id, ].compact a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#matching_keyword_id ⇒ Arel::Node?
39 40 41 |
# File 'lib/queries/tag/filter.rb', line 39 def matching_keyword_id !keyword_id.empty? ? table[:keyword_id].eq_any(keyword_id) : nil end |
#table ⇒ Arel::Table
53 54 55 |
# File 'lib/queries/tag/filter.rb', line 53 def table ::Tag.arel_table end |