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

- (Filter) initialize(params)

Returns a new instance of Filter



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/queries/data_attribute/filter.rb', line 17

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

- (Object) attribute_subject_id

Params specific to DataAttribute



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

def attribute_subject_id
  @attribute_subject_id
end

- (Object) attribute_subject_type

Params specific to DataAttribute



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

def attribute_subject_type
  @attribute_subject_type
end

- (Object) controlled_vocabulary_term_id

Params specific to DataAttribute



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

def controlled_vocabulary_term_id
  @controlled_vocabulary_term_id
end

- (Object) import_predicate

Params specific to DataAttribute



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

def import_predicate
  @import_predicate
end

- (Object) object_global_id

Params specific to DataAttribute



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

def object_global_id
  @object_global_id
end

- (Object) options

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

- (Object) type

Params specific to DataAttribute



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

def type
  @type
end

- (Object) value

Params specific to DataAttribute



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

def value
  @value
end

Instance Method Details

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


101
102
103
104
105
106
107
# File 'lib/queries/data_attribute/filter.rb', line 101

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

- (ActiveRecord::Relation) and_clauses

Returns:

  • (ActiveRecord::Relation)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/queries/data_attribute/filter.rb', line 30

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

- (Arel::Node?) matching_attribute_subject_id

Returns:

  • (Arel::Node, nil)


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

def matching_attribute_subject_id
  !attribute_subject_id.blank? ? table[:attribute_subject_id].eq(attribute_subject_id)  : nil
end

- (Arel::Node?) matching_attribute_subject_type

Returns:

  • (Arel::Node, nil)


61
62
63
# File 'lib/queries/data_attribute/filter.rb', line 61

def matching_attribute_subject_type
  !attribute_subject_type.blank? ? table[:attribute_subject_type].eq(attribute_subject_type)  : nil
end

- (Arel::Node?) matching_controlled_vocabulary_term_id

Returns:

  • (Arel::Node, nil)


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

def matching_controlled_vocabulary_term_id
  controlled_vocabulary_term_id.blank? ? nil : table[:controlled_vocabulary_term_id].eq_any(controlled_vocabulary_term_id)
end

- (Arel::Node?) matching_import_predicate

Returns:

  • (Arel::Node, nil)


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

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

- (Arel::Node?) matching_subject

Returns:

  • (Arel::Node, nil)


50
51
52
53
54
55
56
57
58
# File 'lib/queries/data_attribute/filter.rb', line 50

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

- (Arel::Node?) matching_type

Returns:

  • (Arel::Node, nil)


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

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

- (Arel::Node?) matching_value

Returns:

  • (Arel::Node, nil)


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

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

- (ActiveRecord object?) object_for

TODO: DRY

Returns:

  • (ActiveRecord object, nil)


92
93
94
95
96
97
98
# File 'lib/queries/data_attribute/filter.rb', line 92

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

- (Arel::Table) table

Returns:

  • (Arel::Table)


110
111
112
# File 'lib/queries/data_attribute/filter.rb', line 110

def table
  ::DataAttribute.arel_table
end