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
# 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_type = params[:attribute_subject_type]
  @object_global_id = params[:object_global_id]
  @options = params
end

Instance Attribute Details

- (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)


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

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

- (ActiveRecord::Relation) and_clauses

Returns:

  • (ActiveRecord::Relation)


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

def and_clauses
  clauses = [
    Queries::Annotator.annotator_params(options, ::DataAttribute),
    matching_type,
    matching_value,
    matching_import_predicate,
    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_type

Returns:

  • (Arel::Node, nil)


59
60
61
# File 'lib/queries/data_attribute/filter.rb', line 59

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)


79
80
81
# File 'lib/queries/data_attribute/filter.rb', line 79

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)


69
70
71
# File 'lib/queries/data_attribute/filter.rb', line 69

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

- (Arel::Node?) matching_subject

Returns:

  • (Arel::Node, nil)


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

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)


74
75
76
# File 'lib/queries/data_attribute/filter.rb', line 74

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

- (Arel::Node?) matching_value

Returns:

  • (Arel::Node, nil)


64
65
66
# File 'lib/queries/data_attribute/filter.rb', line 64

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

- (ActiveRecord object?) object_for

TODO: DRY

Returns:

  • (ActiveRecord object, nil)


85
86
87
88
89
90
91
# File 'lib/queries/data_attribute/filter.rb', line 85

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

- (Arel::Table) table

Returns:

  • (Arel::Table)


103
104
105
# File 'lib/queries/data_attribute/filter.rb', line 103

def table
  ::DataAttribute.arel_table
end