Class: Queries::DataAttribute::Filter
- Inherits:
-
Object
- Object
- Queries::DataAttribute::Filter
- Defined in:
- lib/queries/data_attribute/filter.rb
Instance Attribute Summary collapse
-
#attribute_subject_id ⇒ Object
Returns the value of attribute attribute_subject_id.
-
#attribute_subject_type ⇒ Object
Returns the value of attribute attribute_subject_type.
- #controlled_vocabulary_term_id ⇒ Array
-
#import_predicate ⇒ Object
Returns the value of attribute import_predicate.
-
#object_global_id ⇒ Object
Returns the value of attribute object_global_id.
-
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Params specific to DataAttribute.
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_attribute_subject_id ⇒ Arel::Node?
- #matching_attribute_subject_type ⇒ Arel::Node?
- #matching_controlled_vocabulary_term_id ⇒ Arel::Node?
- #matching_import_predicate ⇒ Arel::Node?
- #matching_subject ⇒ Arel::Node?
- #matching_type ⇒ Arel::Node?
- #matching_value ⇒ Arel::Node?
-
#object_for ⇒ ActiveRecord object?
TODO: DRY.
- #table ⇒ Arel::Table
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/queries/data_attribute/filter.rb', line 28 def initialize(params) @value = params[:value] @controlled_vocabulary_term_id = params[:controlled_vocabulary_term_id] @import_predicate = params[:import_predicate] @type = params[:type] @attribute_subject_id = params[:attribute_subject_id] @attribute_subject_type = params[:attribute_subject_type] @object_global_id = params[:object_global_id] @options = params end |
Instance Attribute Details
#attribute_subject_id ⇒ Object
Returns the value of attribute attribute_subject_id.
25 26 27 |
# File 'lib/queries/data_attribute/filter.rb', line 25 def attribute_subject_id @attribute_subject_id end |
#attribute_subject_type ⇒ Object
Returns the value of attribute attribute_subject_type.
23 24 25 |
# File 'lib/queries/data_attribute/filter.rb', line 23 def attribute_subject_type @attribute_subject_type end |
#controlled_vocabulary_term_id ⇒ Array
15 16 17 |
# File 'lib/queries/data_attribute/filter.rb', line 15 def controlled_vocabulary_term_id @controlled_vocabulary_term_id end |
#import_predicate ⇒ Object
Returns the value of attribute import_predicate.
17 18 19 |
# File 'lib/queries/data_attribute/filter.rb', line 17 def import_predicate @import_predicate end |
#object_global_id ⇒ Object
Returns the value of attribute object_global_id.
21 22 23 |
# File 'lib/queries/data_attribute/filter.rb', line 21 def object_global_id @object_global_id end |
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here
9 10 11 |
# File 'lib/queries/data_attribute/filter.rb', line 9 def @options end |
#type ⇒ Object
Returns the value of attribute type.
19 20 21 |
# File 'lib/queries/data_attribute/filter.rb', line 19 def type @type end |
#value ⇒ Object
Params specific to DataAttribute
12 13 14 |
# File 'lib/queries/data_attribute/filter.rb', line 12 def value @value end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
116 117 118 119 120 121 122 |
# File 'lib/queries/data_attribute/filter.rb', line 116 def all if _a = and_clauses ::DataAttribute.where(and_clauses) else ::DataAttribute.all end end |
#and_clauses ⇒ ActiveRecord::Relation
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/queries/data_attribute/filter.rb', line 45 def and_clauses clauses = [ ::Queries::Annotator.annotator_params(, ::DataAttribute), matching_type, matching_value, matching_import_predicate, matching_attribute_subject_id, matching_attribute_subject_type, matching_controlled_vocabulary_term_id, matching_subject ].compact a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#matching_attribute_subject_id ⇒ Arel::Node?
81 82 83 |
# File 'lib/queries/data_attribute/filter.rb', line 81 def matching_attribute_subject_id !attribute_subject_id.blank? ? table[:attribute_subject_id].eq(attribute_subject_id) : nil end |
#matching_attribute_subject_type ⇒ Arel::Node?
76 77 78 |
# File 'lib/queries/data_attribute/filter.rb', line 76 def matching_attribute_subject_type !attribute_subject_type.blank? ? table[:attribute_subject_type].eq(attribute_subject_type) : nil end |
#matching_controlled_vocabulary_term_id ⇒ Arel::Node?
101 102 103 |
# File 'lib/queries/data_attribute/filter.rb', line 101 def matching_controlled_vocabulary_term_id controlled_vocabulary_term_id.empty? ? nil : table[:controlled_vocabulary_term_id].eq_any(controlled_vocabulary_term_id) end |
#matching_import_predicate ⇒ Arel::Node?
91 92 93 |
# File 'lib/queries/data_attribute/filter.rb', line 91 def matching_import_predicate import_predicate.blank? ? nil : table[:import_predicate].eq(import_predicate) end |
#matching_subject ⇒ Arel::Node?
65 66 67 68 69 70 71 72 73 |
# File 'lib/queries/data_attribute/filter.rb', line 65 def matching_subject if o = object_for table['attribute_subject_id'].eq(o.id).and( table['attribute_subject_type'].eq(o..class.name) ) else nil end end |
#matching_type ⇒ Arel::Node?
96 97 98 |
# File 'lib/queries/data_attribute/filter.rb', line 96 def matching_type type.blank? ? nil : table[:type].eq(type) end |
#matching_value ⇒ Arel::Node?
86 87 88 |
# File 'lib/queries/data_attribute/filter.rb', line 86 def matching_value value.blank? ? nil : table[:value].eq(value) end |
#object_for ⇒ ActiveRecord object?
TODO: DRY
107 108 109 110 111 112 113 |
# File 'lib/queries/data_attribute/filter.rb', line 107 def object_for if o = GlobalID::Locator.locate(object_global_id) o else nil end end |
#table ⇒ Arel::Table
125 126 127 |
# File 'lib/queries/data_attribute/filter.rb', line 125 def table ::DataAttribute.arel_table end |