Class: Queries::AlternateValue::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/queries/alternate_value/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



17
18
19
20
21
22
23
# File 'lib/queries/alternate_value/filter.rb', line 17

def initialize(params)
  @value = params[:value]
  @language_id = params[:language_id]
  @type = params[:type]
  @alternate_value_object_attribute = params[:alternate_value_object_attribute]
  @options = params 
end

Instance Attribute Details

#alternate_value_object_attributeObject

Params specific to AlternateValue



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

def alternate_value_object_attribute
  @alternate_value_object_attribute
end

#language_idObject

Params specific to AlternateValue



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

def language_id
  @language_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/alternate_value/filter.rb', line 11

def options
  @options
end

#typeObject

Params specific to AlternateValue



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

def type
  @type
end

#valueObject

Params specific to AlternateValue



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

def value
  @value
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


63
64
65
66
67
68
69
# File 'lib/queries/alternate_value/filter.rb', line 63

def all
  if a = and_clauses
    ::AlternateValue.where(and_clauses)
  else
    ::AlternateValue.none
  end
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/queries/alternate_value/filter.rb', line 26

def and_clauses
  clauses = [
    Queries::Annotator.annotator_params(options, ::AlternateValue),
    matching_value,
    matching_language_id,
    matching_type,
    matching_alternate_value_object_attribute
  ].compact

  a = clauses.shift
  clauses.each do |b|
    a = a.and(b)
  end
  a
end

#matching_alternate_value_object_attributeArel::Node?

Returns:

  • (Arel::Node, nil)


58
59
60
# File 'lib/queries/alternate_value/filter.rb', line 58

def matching_alternate_value_object_attribute
  alternate_value_object_attribute.blank? ? nil : table[:alternate_value_object_attribute].eq(alternate_value_object_attribute) 
end

#matching_language_idArel::Node?

Returns:

  • (Arel::Node, nil)


48
49
50
# File 'lib/queries/alternate_value/filter.rb', line 48

def matching_language_id
  language_id.blank? ? nil : table[:language_id].eq(language_id) 
end

#matching_typeArel::Node?

Returns:

  • (Arel::Node, nil)


53
54
55
# File 'lib/queries/alternate_value/filter.rb', line 53

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

#matching_valueArel::Node?

Returns:

  • (Arel::Node, nil)


43
44
45
# File 'lib/queries/alternate_value/filter.rb', line 43

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

#tableArel::Table

Returns:

  • (Arel::Table)


72
73
74
# File 'lib/queries/alternate_value/filter.rb', line 72

def table
  ::AlternateValue.arel_table
end