Class: Chewy::Search::Parameters::StoredFields
- Defined in:
- lib/chewy/search/parameters/stored_fields.rb
Overview
This storage is basically an array storage, but with an additional ability to pass ‘enabled` option.
Instance Attribute Summary
Attributes inherited from Storage
Instance Method Summary collapse
-
#merge!(other) ⇒ {Symbol => Array<String>, true, false}
Requires an additional logic to merge ‘enabled` value.
-
#render ⇒ {Symbol => Object}?
Renders ‘none` if `stored_fields` are disabled, otherwise renders the array of stored field names.
-
#update!(other_value) ⇒ {Symbol => Array<String>, true, false}
If array or just a field name is passed - it gets concatenated to the storage array.
Methods inherited from Storage
Constructor Details
This class inherits a constructor from Chewy::Search::Parameters::Storage
Instance Method Details
#merge!(other) ⇒ {Symbol => Array<String>, true, false}
Requires an additional logic to merge ‘enabled` value.
30 31 32 33 |
# File 'lib/chewy/search/parameters/stored_fields.rb', line 30 def merge!(other) update!(other.value[:stored_fields]) update!(other.value[:enabled]) end |
#render ⇒ {Symbol => Object}?
Renders ‘none` if `stored_fields` are disabled, otherwise renders the array of stored field names.
40 41 42 43 44 45 46 |
# File 'lib/chewy/search/parameters/stored_fields.rb', line 40 def render if !value[:enabled] {self.class.param_name => '_none_'} elsif value[:stored_fields].present? {self.class.param_name => value[:stored_fields]} end end |
#update!(other_value) ⇒ {Symbol => Array<String>, true, false}
If array or just a field name is passed - it gets concatenated to the storage array. ‘true` or `false` values are modifying `enabled` parameter.
19 20 21 22 23 |
# File 'lib/chewy/search/parameters/stored_fields.rb', line 19 def update!(other_value) new_value = normalize(other_value) new_value[:stored_fields] = value[:stored_fields] | new_value[:stored_fields] @value = new_value end |