Class: Chewy::Search::Parameters::Order
- Defined in:
- lib/chewy/search/parameters/order.rb
Overview
Sort parameter storage. Stores a hash of fields with the nil
key if no options for the field were specified. Normalizer
accepts an array of any hash-string-symbols combinations, or a hash.
Instance Attribute Summary
Attributes inherited from Storage
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Comparison also reqires additional logic.
-
#render ⇒ {Symbol => Array<Hash, String, Symbol>}
Size requires specialized rendering logic, it should return an array to satisfy ES.
-
#update!(other_value) ⇒ Object
Merges two hashes.
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
Comparison also reqires additional logic. Hashes are compared
orderlessly, but for sort
parameter oder is important, so we
compare hash key collections additionally.
43 44 45 |
# File 'lib/chewy/search/parameters/order.rb', line 43 def ==(other) super && value.keys == other.value.keys end |
#render ⇒ {Symbol => Array<Hash, String, Symbol>}
Size requires specialized rendering logic, it should return an array to satisfy ES.
28 29 30 31 32 33 34 35 |
# File 'lib/chewy/search/parameters/order.rb', line 28 def render return if value.blank? sort = value.map do |(field, )| ? {field => } : field end {sort: sort} end |
#update!(other_value) ⇒ Object
Merges two hashes.
19 20 21 |
# File 'lib/chewy/search/parameters/order.rb', line 19 def update!(other_value) value.merge!(normalize(other_value)) end |