class Chewy::Search::Parameters::StoredFields

This storage is basically an array storage, but with an additional ability to pass ‘enabled` option.

@see Chewy::Search::Request#stored_fields @see www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-stored-fields.html

Public Instance Methods

merge!(other) click to toggle source

Requires an additional logic to merge ‘enabled` value.

@see Chewy::Search::Parameters::Storage#merge! @param other [Chewy::Search::Parameters::Storage] other storage @return [{Symbol => Array<String>, true, false}] updated value

# File lib/chewy/search/parameters/stored_fields.rb, line 30
def merge!(other)
  update!(other.value[:stored_fields])
  update!(other.value[:enabled])
end
render() click to toggle source

Renders ‘none` if `stored_fields` are disabled, otherwise renders the array of stored field names.

@see Chewy::Search::Parameters::Storage#render @return [{Symbol => Object}, nil] rendered value with the parameter name

# 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) click to toggle source

If array or just a field name is passed - it gets concatenated to the storage array. ‘true` or `false` values are modifying `enabled` parameter.

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

# 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

Private Instance Methods

normalize(raw_value) click to toggle source
# File lib/chewy/search/parameters/stored_fields.rb, line 50
def normalize(raw_value)
  stored_fields, enabled = case raw_value
  when TrueClass, FalseClass
    [[], raw_value]
  else
    [raw_value, true]
  end
  {stored_fields: Array.wrap(stored_fields).reject(&:blank?).map(&:to_s),
   enabled: enabled}
end