Class: Queries::DataAttribute::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/queries/data_attribute/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject

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_typeObject

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_idArray

Returns:

  • (Array)


15
16
17
# File 'lib/queries/data_attribute/filter.rb', line 15

def controlled_vocabulary_term_id
  @controlled_vocabulary_term_id
end

#import_predicateObject

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_idObject

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

#optionsObject

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
  @options
end

#typeObject

Returns the value of attribute type.



19
20
21
# File 'lib/queries/data_attribute/filter.rb', line 19

def type
  @type
end

#valueObject

Params specific to DataAttribute



12
13
14
# File 'lib/queries/data_attribute/filter.rb', line 12

def value
  @value
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (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_clausesActiveRecord::Relation

Returns:

  • (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(options, ::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_idArel::Node?

Returns:

  • (Arel::Node, nil)


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_typeArel::Node?

Returns:

  • (Arel::Node, nil)


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_idArel::Node?

Returns:

  • (Arel::Node, nil)


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_predicateArel::Node?

Returns:

  • (Arel::Node, nil)


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_subjectArel::Node?

Returns:

  • (Arel::Node, nil)


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.metamorphosize.class.name)
    )
  else
    nil
  end
end

#matching_typeArel::Node?

Returns:

  • (Arel::Node, nil)


96
97
98
# File 'lib/queries/data_attribute/filter.rb', line 96

def matching_type
  type.blank? ? nil : table[:type].eq(type)
end

#matching_valueArel::Node?

Returns:

  • (Arel::Node, nil)


86
87
88
# File 'lib/queries/data_attribute/filter.rb', line 86

def matching_value
  value.blank? ? nil : table[:value].eq(value)
end

#object_forActiveRecord object?

TODO: DRY

Returns:

  • (ActiveRecord object, nil)


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

#tableArel::Table

Returns:

  • (Arel::Table)


125
126
127
# File 'lib/queries/data_attribute/filter.rb', line 125

def table
  ::DataAttribute.arel_table
end