Class: Chewy::Search::Parameters::Indices

Inherits:
Storage
  • Object
show all
Defined in:
lib/chewy/search/parameters/indices.rb

Overview

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.

Instance Attribute Summary

Attributes inherited from Storage

#value

Instance Method Summary collapse

Methods inherited from Storage

#initialize, #merge!, #replace!

Constructor Details

This class inherits a constructor from Chewy::Search::Parameters::Storage

Instance Method Details

#==(other) ⇒ true, false

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

Parameters:

Returns:

  • (true, false)

    the result of comparison

See Also:



19
20
21
# File 'lib/chewy/search/parameters/indices.rb', line 19

def ==(other)
  super || (other.class == self.class && other.render == render)
end

#indicesArray<Chewy::Index>

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

Returns:



46
47
48
# File 'lib/chewy/search/parameters/indices.rb', line 46

def indices
  index_classes
end

#render{Symbol => Array<String>}

Returns desired index names.

Returns:

  • ({Symbol => Array<String>})

    rendered value with the parameter name

See Also:



38
39
40
# File 'lib/chewy/search/parameters/indices.rb', line 38

def render
  {index: index_names.uniq.sort}.reject { |_, v| v.blank? }
end

#update!(other_value) ⇒ {Symbol => Array<Chewy::Index, String, Symbol>}

Just adds indices to indices.

Parameters:

  • other_value ({Symbol => Array<Chewy::Index, String, Symbol>})

    any acceptable storage value

Returns:

  • ({Symbol => Array<Chewy::Index, String, Symbol>})

    updated value

See Also:



28
29
30
31
32
# 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