Class: Queries::Identifier::Filter
- Inherits:
-
Object
- Object
- Queries::Identifier::Filter
- Includes:
- Concerns::Polymorphic
- Defined in:
- lib/queries/identifier/filter.rb
Overview
!! does not inherit from Queries::Query
Instance Attribute Summary collapse
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#identifier_object_id ⇒ Object
Returns the value of attribute identifier_object_id.
-
#identifier_object_ids ⇒ Object
Returns the value of attribute identifier_object_ids.
-
#identifier_object_type ⇒ Object
Returns the value of attribute identifier_object_type.
-
#identifier_object_types ⇒ Object
Returns the value of attribute identifier_object_types.
-
#namespace_id ⇒ Object
Returns the value of attribute namespace_id.
-
#namespace_name ⇒ Object
Returns the value of attribute namespace_name.
-
#namespace_short_name ⇒ Object
Returns the value of attribute namespace_short_name.
-
#object_global_id ⇒ Object
Probably turn it into component parts.
-
#query_string ⇒ Object
A fully qualified identifier, matches cached !! This is the only wildcarded value !!.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_cached ⇒ Arel::Node?
- #matching_identifier_attribute(attribute) ⇒ Arel::Node?
- #matching_identifier_object_ids ⇒ Arel::Node?
- #matching_identifier_object_types ⇒ Arel::Node?
- #matching_namespace(attribute) ⇒ Object
- #merge_clauses ⇒ Object
- #missmatch_with_global_object? ⇒ Boolean
- #missmatched_object_id? ⇒ Boolean
- #missmatched_object_type? ⇒ Boolean
- #table ⇒ Arel::Table
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/queries/identifier/filter.rb', line 30 def initialize(params) @query_string = params[:query_string] @namespace_id = params[:namespace_id] @identifier = params[:identifier] @namespace_short_name = params[:namespace_short_name] @namespace_name = params[:namespace_name] @identifier_object_type = params[:identifier_object_type] @identifier_object_id = params[:identifier_object_id] # TODO: deprecate, see README.md @identifier_object_ids = params[:identifier_object_ids] || [] @identifier_object_types = params[:identifier_object_types] || [] @type = params[:type] @object_global_id = params[:object_global_id] set_polymorphic_ids(params) # need 'set annotator params' end |
Instance Attribute Details
#identifier ⇒ Object
Returns the value of attribute identifier.
14 15 16 |
# File 'lib/queries/identifier/filter.rb', line 14 def identifier @identifier end |
#identifier_object_id ⇒ Object
Returns the value of attribute identifier_object_id.
20 21 22 |
# File 'lib/queries/identifier/filter.rb', line 20 def identifier_object_id @identifier_object_id end |
#identifier_object_ids ⇒ Object
Returns the value of attribute identifier_object_ids.
21 22 23 |
# File 'lib/queries/identifier/filter.rb', line 21 def identifier_object_ids @identifier_object_ids end |
#identifier_object_type ⇒ Object
Returns the value of attribute identifier_object_type.
20 21 22 |
# File 'lib/queries/identifier/filter.rb', line 20 def identifier_object_type @identifier_object_type end |
#identifier_object_types ⇒ Object
Returns the value of attribute identifier_object_types.
22 23 24 |
# File 'lib/queries/identifier/filter.rb', line 22 def identifier_object_types @identifier_object_types end |
#namespace_id ⇒ Object
Returns the value of attribute namespace_id.
16 17 18 |
# File 'lib/queries/identifier/filter.rb', line 16 def namespace_id @namespace_id end |
#namespace_name ⇒ Object
Returns the value of attribute namespace_name.
18 19 20 |
# File 'lib/queries/identifier/filter.rb', line 18 def namespace_name @namespace_name end |
#namespace_short_name ⇒ Object
Returns the value of attribute namespace_short_name.
17 18 19 |
# File 'lib/queries/identifier/filter.rb', line 17 def namespace_short_name @namespace_short_name end |
#object_global_id ⇒ Object
Probably turn it into component parts
27 28 29 |
# File 'lib/queries/identifier/filter.rb', line 27 def object_global_id @object_global_id end |
#query_string ⇒ Object
A fully qualified identifier, matches cached !! This is the only wildcarded value !!
12 13 14 |
# File 'lib/queries/identifier/filter.rb', line 12 def query_string @query_string end |
#type ⇒ Object
Returns the value of attribute type.
24 25 26 |
# File 'lib/queries/identifier/filter.rb', line 24 def type @type end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/queries/identifier/filter.rb', line 164 def all a = and_clauses b = merge_clauses if a && b b.where(a).distinct elsif a ::Identifier.where(a).distinct elsif b b.distinct else ::Identifier.all end end |
#and_clauses ⇒ ActiveRecord::Relation
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/queries/identifier/filter.rb', line 81 def and_clauses clauses = [ # Queries::Annotator.annotator_params(options, ::Identifier), matching_cached, matching_identifier_attribute(:identifier), matching_identifier_attribute(:namespace_id), matching_identifier_attribute(:identifier_object_type), matching_identifier_attribute(:identifier_object_id), matching_identifier_attribute(:type), matching_identifier_object_types, matching_polymorphic_ids ].compact a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#matching_cached ⇒ Arel::Node?
117 118 119 |
# File 'lib/queries/identifier/filter.rb', line 117 def matching_cached query_string.blank? ? nil : table[:cached].matches('%' + query_string + '%') end |
#matching_identifier_attribute(attribute) ⇒ Arel::Node?
132 133 134 135 |
# File 'lib/queries/identifier/filter.rb', line 132 def matching_identifier_attribute(attribute) v = send(attribute) v.blank? ? nil : table[attribute].eq(v) end |
#matching_identifier_object_ids ⇒ Arel::Node?
122 123 124 |
# File 'lib/queries/identifier/filter.rb', line 122 def matching_identifier_object_ids identifier_object_ids.empty? ? nil : table[:identifier_object_id].eq_any(matching_identifier_object_ids) end |
#matching_identifier_object_types ⇒ Arel::Node?
127 128 129 |
# File 'lib/queries/identifier/filter.rb', line 127 def matching_identifier_object_types identifier_object_types.empty? ? nil : table[:identifier_object_type].eq_any(identifier_object_types) end |
#matching_namespace(attribute) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/queries/identifier/filter.rb', line 137 def matching_namespace(attribute) v = self.send("namespace_#{attribute}") return nil if v.blank? o = table n = ::Namespace.arel_table a = o.alias("a_") b = o.project(a[Arel.star]).from(a) c = n.alias('n1') b = b.join(c, Arel::Nodes::OuterJoin) .on( a[:namespace_id].eq(c[:id]) ) e = c[:id].not_eq(nil) f = c[attribute].eq(v) b = b.where(e.and(f)) b = b.group(a['id']) b = b.as('z5_') ::Identifier.joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['id'].eq(o['id'])))) end |
#merge_clauses ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/queries/identifier/filter.rb', line 101 def merge_clauses clauses = [ matching_namespace(:short_name), matching_namespace(:name), ].compact return nil if clauses.empty? a = clauses.shift clauses.each do |b| a = a.merge(b) end a end |
#missmatch_with_global_object? ⇒ Boolean
64 65 66 |
# File 'lib/queries/identifier/filter.rb', line 64 def missmatch_with_global_object? missmatched_object_id? || missmatched_object_type? end |
#missmatched_object_id? ⇒ Boolean
52 53 54 55 56 |
# File 'lib/queries/identifier/filter.rb', line 52 def missmatched_object_id? return false if @identifier_object_id.blank? || @object_global_id.blank? o = GlobalID::Locator.locate(object_global_id) !(o.id == @identifier_object_id) end |
#missmatched_object_type? ⇒ Boolean
58 59 60 61 62 |
# File 'lib/queries/identifier/filter.rb', line 58 def missmatched_object_type? return false if @identifier_object_id.blank? || @object_global_id.blank? o = GlobalID::Locator.locate(object_global_id) !(o.class.base_class.name == @identifier_object_type) end |
#table ⇒ Arel::Table
179 180 181 |
# File 'lib/queries/identifier/filter.rb', line 179 def table ::Identifier.arel_table end |