Class: Queries::AlternateValue::Filter

Inherits:
Query::Filter show all
Includes:
Concerns::Polymorphic, Helpers
Defined in:
lib/queries/alternate_value/filter.rb

Constant Summary collapse

PARAMS =
[
  *::AlternateValue.related_foreign_keys.map(&:to_sym),
  :alternate_value_id,
  :value,
  :language_id,
  :type,
  :alternate_value_object_attribute,
  :alternate_value_object_id,
  :alternate_value_object_type,
  alternate_value_id: []
].freeze

Constants inherited from Query::Filter

Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES

Instance Attribute Summary collapse

Attributes inherited from Query::Filter

#api, #asserted_distribution_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #data_attribute_query, #descriptor_query, #extract_query, #image_query, #loan_query, #object_global_id, #observation_query, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #taxon_name_query

Attributes inherited from Query

#query_string, #terms

Instance Method Summary collapse

Methods included from Helpers

#boolean_param

Methods inherited from Query::Filter

#all, #all_and_clauses, #all_merge_clauses, #annotator_and_clauses, #annotator_merge_clauses, annotator_params, api_except_params, api_excluded_params, #attribute_exact_facet, #deep_permit, included_annotator_facets, inverted_subqueries, #merge_clauses, #model_id_facet, #object_global_id_facet, params, #permitted_params, #set_nested_queries, #shared_and_clauses, #subquery_vector

Methods inherited from Query

#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces

Constructor Details

#initialize(query_params) ⇒ Filter

Returns a new instance of Filter.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/queries/alternate_value/filter.rb', line 32

def initialize(query_params)
  super
  @alternate_value_id = params[:alternate_value_id]
  @alternate_value_object_attribute = params[:alternate_value_object_attribute]
  @alternate_value_object_type = params[:alternate_value_object_type]
  @alternate_value_object_id = params[:alternate_value_object_id]
  @language_id = params[:language_id]
  @type = params[:type]
  @value = params[:value]
  set_polymorphic_params(params)
end

Instance Attribute Details

#alternate_value_idArray

Returns:

  • (Array)


22
23
24
# File 'lib/queries/alternate_value/filter.rb', line 22

def alternate_value_id
  @alternate_value_id
end

#alternate_value_object_attributeObject

Params specific to AlternateValue



25
26
27
# File 'lib/queries/alternate_value/filter.rb', line 25

def alternate_value_object_attribute
  @alternate_value_object_attribute
end

#alternate_value_object_idObject

Returns the value of attribute alternate_value_object_id.



27
28
29
# File 'lib/queries/alternate_value/filter.rb', line 27

def alternate_value_object_id
  @alternate_value_object_id
end

#alternate_value_object_typeObject

Returns the value of attribute alternate_value_object_type.



29
30
31
# File 'lib/queries/alternate_value/filter.rb', line 29

def alternate_value_object_type
  @alternate_value_object_type
end

#language_idObject

Params specific to AlternateValue



25
26
27
# File 'lib/queries/alternate_value/filter.rb', line 25

def language_id
  @language_id
end

#typeObject

Params specific to AlternateValue



25
26
27
# File 'lib/queries/alternate_value/filter.rb', line 25

def type
  @type
end

#valueObject

Params specific to AlternateValue



25
26
27
# File 'lib/queries/alternate_value/filter.rb', line 25

def value
  @value
end

Instance Method Details

#alternate_value_object_attribute_facetArel::Node?

Returns:

  • (Arel::Node, nil)


100
101
102
# File 'lib/queries/alternate_value/filter.rb', line 100

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

#alternate_value_object_id_facetObject



67
68
69
70
# File 'lib/queries/alternate_value/filter.rb', line 67

def alternate_value_object_id_facet
  return nil if alternate_value_object_id.empty?
  table[:alternate_value_object_id].in(alternate_value_object_id)
end

#alternate_value_object_type_facetObject



62
63
64
65
# File 'lib/queries/alternate_value/filter.rb', line 62

def alternate_value_object_type_facet
  return nil if alternate_value_object_type.empty?
  table[:alternate_value_object_type].in(alternate_value_object_type)
end

#and_clausesObject



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/queries/alternate_value/filter.rb', line 104

def and_clauses
  [
    alternate_value_object_id_facet,
    alternate_value_object_type_facet,
    value_facet,
    language_id_facet,
    type_facet,
    alternate_value_object_attribute_facet,
    community_project_id_facet,
  ]
end

#community_project_id_facetObject



72
73
74
75
76
77
78
# File 'lib/queries/alternate_value/filter.rb', line 72

def community_project_id_facet
  return nil if project_id.nil?
  if !ignores_project?
    return table[:project_id].in(project_id)
  end
  nil
end

#ignores_project?Boolean

Returns:

  • (Boolean)


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

def ignores_project?
  ::AlternateValue::ALWAYS_COMMUNITY.include?( polymorphic_type )
end

#language_id_facetObject



89
90
91
92
# File 'lib/queries/alternate_value/filter.rb', line 89

def language_id_facet
  return nil if language_id.blank?
  table[:language_id].eq(language_id)
end

#project_id_facetObject



80
81
82
# File 'lib/queries/alternate_value/filter.rb', line 80

def project_id_facet
  nil
end

#type_facetObject



94
95
96
97
# File 'lib/queries/alternate_value/filter.rb', line 94

def type_facet
  return nil if type.blank?
  table[:type].eq(type)
end

#value_facetObject



84
85
86
87
# File 'lib/queries/alternate_value/filter.rb', line 84

def value_facet
  return nil if value.blank?
  table[:value].eq(value)
end