Class: Mongoid::QueryStringInterface::Parsers::FiltersParser
- Inherits:
-
Object
- Object
- Mongoid::QueryStringInterface::Parsers::FiltersParser
- Includes:
- Helpers
- Defined in:
- lib/mongoid/parsers/filters_parser.rb
Instance Attribute Summary collapse
-
#default_filters ⇒ Object
readonly
Returns the value of attribute default_filters.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
Instance Method Summary collapse
- #filter_parsers ⇒ Object
-
#initialize(filters, default_filters = {}, attributes_to_replace = {}, raw_filters = nil) ⇒ FiltersParser
constructor
A new instance of FiltersParser.
- #parse ⇒ Object
Methods included from Helpers
#hash_with_indifferent_access, #replace_attribute, #replaced_attribute_name, #replaced_attribute_value
Constructor Details
#initialize(filters, default_filters = {}, attributes_to_replace = {}, raw_filters = nil) ⇒ FiltersParser
Returns a new instance of FiltersParser.
9 10 11 12 13 14 |
# File 'lib/mongoid/parsers/filters_parser.rb', line 9 def initialize(filters, default_filters={}, attributes_to_replace={}, raw_filters=nil) @filters = filters.with_indifferent_access @default_filters = default_filters.with_indifferent_access @attributes_to_replace = attributes_to_replace.with_indifferent_access @raw_filters = raw_filters.nil? ? @filters : raw_filters.with_indifferent_access end |
Instance Attribute Details
#default_filters ⇒ Object (readonly)
Returns the value of attribute default_filters.
7 8 9 |
# File 'lib/mongoid/parsers/filters_parser.rb', line 7 def default_filters @default_filters end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
7 8 9 |
# File 'lib/mongoid/parsers/filters_parser.rb', line 7 def filters @filters end |
Instance Method Details
#filter_parsers ⇒ Object
25 26 27 28 29 |
# File 'lib/mongoid/parsers/filters_parser.rb', line 25 def filter_parsers @filter_parsers ||= filters.map do |raw_attribute, raw_value| FilterParser.new(raw_attribute, raw_value, @attributes_to_replace, @raw_filters) end end |
#parse ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/mongoid/parsers/filters_parser.rb', line 16 def parse result = default_filters.inject({}) do |result, item| raw_attribute, raw_value = item result[replaced_attribute_name(raw_attribute, @attributes_to_replace).to_s] = replaced_attribute_value(raw_attribute, raw_value, @attributes_to_replace, @raw_filters) result end result.merge(parsed_filters) end |