Class: Chewy::Search::Parameters::Source
- Defined in:
- lib/chewy/search/parameters/source.rb
Overview
This storage handles either an array of strings/symbols
or a hash with includes
and excludes
keys and
arrays of strings/symbols as values. Any other key is ignored.
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
false
ifsource
is disabled, otherwise renders the contents ofincludes
value or even the entire hash ifexcludes
also specified. -
#update!(other_value) ⇒ {Symbol => Array<String>, true, false}
If array or simple string/symbol is passed, it is treated as a part of
includes
array and gets concatenated with it.
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.
34 35 36 37 |
# File 'lib/chewy/search/parameters/source.rb', line 34 def merge!(other) super update!(other.value[:enabled]) end |
#render ⇒ {Symbol => Object}?
Renders false
if source
is disabled, otherwise renders the
contents of includes
value or even the entire hash if excludes
also specified.
45 46 47 48 49 50 51 52 53 |
# File 'lib/chewy/search/parameters/source.rb', line 45 def render if !value[:enabled] {self.class.param_name => false} elsif value[:excludes].present? {self.class.param_name => value.slice(:includes, :excludes).reject { |_, v| v.blank? }} elsif value[:includes].present? {self.class.param_name => value[:includes]} end end |
#update!(other_value) ⇒ {Symbol => Array<String>, true, false}
If array or simple string/symbol is passed, it is treated
as a part of includes
array and gets concatenated with it.
In case of hash, respective values are concatenated as well.
22 23 24 25 26 27 |
# File 'lib/chewy/search/parameters/source.rb', line 22 def update!(other_value) new_value = normalize(other_value) new_value[:includes] = value[:includes] | new_value[:includes] new_value[:excludes] = value[:excludes] | new_value[:excludes] @value = new_value end |