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

- (Filter) initialize(params)

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

- (Object) alternate_value_object_attribute

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

- (Object) language_id

Params specific to AlternateValue



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

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

def options
  @options
end

- (Object) type

Params specific to AlternateValue



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

def type
  @type
end

- (Object) value

Params specific to AlternateValue



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

def value
  @value
end

Instance Method Details

- (ActiveRecord::Relation) all

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

- (ActiveRecord::Relation) and_clauses

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

- (Arel::Node?) matching_alternate_value_object_attribute

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

- (Arel::Node?) matching_language_id

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

- (Arel::Node?) matching_type

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

- (Arel::Node?) matching_value

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

- (Arel::Table) table

Returns:

  • (Arel::Table)


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

def table
  ::AlternateValue.arel_table
end