Class: Queries::DataAttribute::Filter

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

Overview

!! does not inherit from base query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Filter

Returns a new instance of Filter



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/queries/data_attribute/filter.rb', line 22

def initialize(params)
  @value = params[:value]
  @controlled_vocabulary_term_id = [params[:controlled_vocabulary_term_id]].flatten.compact
  @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



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

def attribute_subject_id
  @attribute_subject_id
end

#attribute_subject_typeObject

Returns the value of attribute attribute_subject_type



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

def attribute_subject_type
  @attribute_subject_type
end

#controlled_vocabulary_term_idArray

Returns:

  • (Array)


17
18
19
# File 'lib/queries/data_attribute/filter.rb', line 17

def controlled_vocabulary_term_id
  @controlled_vocabulary_term_id
end

#import_predicateObject

Returns the value of attribute import_predicate



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

def import_predicate
  @import_predicate
end

#object_global_idObject

Returns the value of attribute object_global_id



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

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



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

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



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

def value
  @value
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


106
107
108
109
110
111
112
# File 'lib/queries/data_attribute/filter.rb', line 106

def all
  if _a = and_clauses
    ::DataAttribute.where(and_clauses)
  else
    ::DataAttribute.all
  end
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/queries/data_attribute/filter.rb', line 35

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)


71
72
73
# File 'lib/queries/data_attribute/filter.rb', line 71

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)


66
67
68
# File 'lib/queries/data_attribute/filter.rb', line 66

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)


91
92
93
# File 'lib/queries/data_attribute/filter.rb', line 91

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)


81
82
83
# File 'lib/queries/data_attribute/filter.rb', line 81

def matching_import_predicate
  import_predicate.blank? ? nil : table[:import_predicate].eq(import_predicate)
end

#matching_subjectArel::Node?

Returns:

  • (Arel::Node, nil)


55
56
57
58
59
60
61
62
63
# File 'lib/queries/data_attribute/filter.rb', line 55

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)


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

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

#matching_valueArel::Node?

Returns:

  • (Arel::Node, nil)


76
77
78
# File 'lib/queries/data_attribute/filter.rb', line 76

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

#object_forActiveRecord object?

TODO: DRY

Returns:

  • (ActiveRecord object, nil)


97
98
99
100
101
102
103
# File 'lib/queries/data_attribute/filter.rb', line 97

def object_for
  if o = GlobalID::Locator.locate(object_global_id)
    o
  else
    nil
  end
end

#tableArel::Table

Returns:

  • (Arel::Table)


115
116
117
# File 'lib/queries/data_attribute/filter.rb', line 115

def table
  ::DataAttribute.arel_table
end