class Chewy::Search::Parameters::Indices

Stores indices to query. Renders it to lists of string accepted by ElasticSearch API.

If index is added to the storage, no matter, a class or a string/symbol, it gets appended to the list.

Public Instance Methods

==(other) click to toggle source

Two index storages are equal if they produce the same output on render.

@see Chewy::Search::Parameters::Storage#== @param other [Chewy::Search::Parameters::Storage] any storage instance @return [true, false] the result of comparison

Calls superclass method
# File lib/chewy/search/parameters/indices.rb, line 19
def ==(other)
  super || (other.class == self.class && other.render == render)
end
indices() click to toggle source

Returns index classes used for the request. No strings/symbols included.

@return [Array<Chewy::Index>] a list of index classes

# File lib/chewy/search/parameters/indices.rb, line 46
def indices
  index_classes
end
render() click to toggle source

Returns desired index names.

@see Chewy::Search::Parameters::Storage#render @return [{Symbol => Array<String>}] rendered value with the parameter name

# File lib/chewy/search/parameters/indices.rb, line 38
def render
  {index: index_names.uniq.sort}.reject { |_, v| v.blank? }
end
update!(other_value) click to toggle source

Just adds indices to indices.

@see Chewy::Search::Parameters::Storage#update! @param other_value [{Symbol => Array<Chewy::Index, String, Symbol>}] any acceptable storage value @return [{Symbol => Array<Chewy::Index, String, Symbol>}] updated value

# File lib/chewy/search/parameters/indices.rb, line 28
def update!(other_value)
  new_value = normalize(other_value)

  @value = {indices: value[:indices] | new_value[:indices]}
end

Private Instance Methods

index_classes() click to toggle source
# File lib/chewy/search/parameters/indices.rb, line 62
def index_classes
  value[:indices].select do |klass|
    klass.is_a?(Class) && klass < Chewy::Index
  end
end
index_identifiers() click to toggle source
# File lib/chewy/search/parameters/indices.rb, line 68
def index_identifiers
  value[:indices] - index_classes
end
index_names() click to toggle source
# File lib/chewy/search/parameters/indices.rb, line 72
def index_names
  indices.map(&:index_name) | index_identifiers.map(&:to_s)
end
initialize_clone(origin) click to toggle source
# File lib/chewy/search/parameters/indices.rb, line 52
def initialize_clone(origin)
  @value = origin.value.dup
end
normalize(value) click to toggle source
# File lib/chewy/search/parameters/indices.rb, line 56
def normalize(value)
  value ||= {}

  {indices: Array.wrap(value[:indices]).flatten.compact}
end