Class: Chewy::Search::Parameters::StoredFields

Inherits:
Storage
  • Object
show all
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

#value

Instance Method Summary collapse

Methods inherited from Storage

#==, #initialize, #replace!

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.

Parameters:

Returns:

  • ({Symbol => Array<String>, true, false})

    updated value

See Also:



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.

Returns:

  • ({Symbol => Object}, nil)

    rendered value with the parameter name

See Also:



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.

Parameters:

  • other_value (true, false, String, Symbol, Array<String, Symbol>)

    any acceptable storage value

Returns:

  • ({Symbol => Array<String>, true, false})

    updated value

See Also:



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