Class: Mongoid::QueryStringInterface::Parsers::FiltersParser

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/mongoid/parsers/filters_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_filtersObject (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

#filtersObject (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_parsersObject



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

#parseObject



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