Module: Mongoid::QueryStringInterface::Helpers

Included in:
Parsers::FilterParser, Parsers::FiltersParser
Defined in:
lib/mongoid/helpers.rb

Instance Method Summary collapse

Instance Method Details

#hash_with_indifferent_access(params) ⇒ Object



4
5
6
# File 'lib/mongoid/helpers.rb', line 4

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



8
9
10
11
# File 'lib/mongoid/helpers.rb', line 8

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



13
14
15
16
# File 'lib/mongoid/helpers.rb', line 13

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



18
19
20
21
# File 'lib/mongoid/helpers.rb', line 18

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