Class: Queries::Tag::Filter
- Inherits:
-
Object
- Object
- Queries::Tag::Filter
- Includes:
- Concerns::Polymorphic
- Defined in:
- lib/queries/tag/filter.rb
Overview
!! does not inherit from base query
Instance Attribute Summary collapse
-
#keyword_id ⇒ Object
Array, Integer.
-
#tag_object_id ⇒ Object
Array, Integer.
-
#tag_object_type ⇒ Object
Array, Integer.
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?
- #matching_tag_object_id ⇒ Arel::Node?
- #matching_tag_object_type ⇒ Arel::Node?
- #table ⇒ Arel::Table
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
23 24 25 26 27 28 29 30 |
# File 'lib/queries/tag/filter.rb', line 23 def initialize(params) @keyword_id = [params[:keyword_id]].flatten.compact @tag_object_type = params[:tag_object_type] @tag_object_id = params[:tag_object_id] @object_global_id = params[:object_global_id] set_polymorphic_ids(params) end |
Instance Attribute Details
#keyword_id ⇒ Object
Array, Integer
11 12 13 |
# File 'lib/queries/tag/filter.rb', line 11 def keyword_id @keyword_id end |
#tag_object_id ⇒ Object
Array, Integer
17 18 19 |
# File 'lib/queries/tag/filter.rb', line 17 def tag_object_id @tag_object_id end |
#tag_object_type ⇒ Object
Array, Integer
14 15 16 |
# File 'lib/queries/tag/filter.rb', line 14 def tag_object_type @tag_object_type end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
73 74 75 76 77 78 79 |
# File 'lib/queries/tag/filter.rb', line 73 def all if a = and_clauses ::Tag.where(and_clauses).distinct else ::Tag.all end end |
#and_clauses ⇒ ActiveRecord::Relation
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/queries/tag/filter.rb', line 41 def and_clauses clauses = [ # ::Queries::Annotator.annotator_params(options, ::Tag), matching_keyword_id, matching_polymorphic_ids, matching_tag_object_id, matching_tag_object_type, ].compact a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#matching_keyword_id ⇒ Arel::Node?
58 59 60 |
# File 'lib/queries/tag/filter.rb', line 58 def matching_keyword_id !keyword_id.empty? ? table[:keyword_id].eq_any(keyword_id) : nil end |
#matching_tag_object_id ⇒ Arel::Node?
63 64 65 |
# File 'lib/queries/tag/filter.rb', line 63 def matching_tag_object_id tag_object_id.empty? ? nil : table[:tag_object_id].eq_any(tag_object_id) end |
#matching_tag_object_type ⇒ Arel::Node?
68 69 70 |
# File 'lib/queries/tag/filter.rb', line 68 def matching_tag_object_type tag_object_type.empty? ? nil : table[:tag_object_type].eq_any(tag_object_type) end |
#table ⇒ Arel::Table
82 83 84 |
# File 'lib/queries/tag/filter.rb', line 82 def table ::Tag.arel_table end |