Module: QueryStringInterface::Helpers

Included in:
Filter, FilterCollection, SortingFilters
Defined in:
lib/query_string_interface/helpers.rb

Instance Method Summary collapse

Instance Method Details

#hash_with_indifferent_access(params) ⇒ Object



3
4
5
# File 'lib/query_string_interface/helpers.rb', line 3

def hash_with_indifferent_access(params)
  params.is_a?(HashWithIndifferentAccess) ? params : params.with_indifferent_access
end

#replace_attribute(attribute, hash_with_attributes_to_replace) ⇒ Object



7
8
9
10
# File 'lib/query_string_interface/helpers.rb', line 7

def replace_attribute(attribute, hash_with_attributes_to_replace)
  hash = hash_with_indifferent_access(hash_with_attributes_to_replace)
  hash.has_key?(attribute) ? hash[attribute] : attribute
end

#replaced_attribute_name(attribute, hash_with_attributes_to_replace) ⇒ Object



12
13
14
15
# File 'lib/query_string_interface/helpers.rb', line 12

def replaced_attribute_name(attribute, hash_with_attributes_to_replace)
  attribute = replace_attribute(attribute, hash_with_attributes_to_replace)
  attribute.is_a?(Hash) ? attribute[:to] : attribute
end

#replaced_attribute_value(attribute, value, hash_with_attributes_to_replace, raw_params) ⇒ Object



17
18
19
20
# File 'lib/query_string_interface/helpers.rb', line 17

def replaced_attribute_value(attribute, value, hash_with_attributes_to_replace, raw_params)
  attribute = replace_attribute(attribute, hash_with_attributes_to_replace)
  attribute.is_a?(Hash) ? attribute[:convert_value_to].call(value, raw_params) : value
end