Class: Paraphrase::ParamsFilter
- Inherits:
-
Object
- Object
- Paraphrase::ParamsFilter
- Defined in:
- lib/paraphrase/params_filter.rb
Overview
ParamsFilter is responsible for processing the query params the Query object was initialized with.
In the following order, it:
- Removes all keys not mapped to a model scope
- Pre-processes the query param if a pre-processor is defined
- Recursively removes blank values from the value
- Removes the param if the pre-processed, scrubbed value is
blank?
Each Query subclass has its own ParamsFilter subclass defined on inheritance that can be customized to pre-process query params. The class can be re-opened inside the Query class definition or by calling the param class method.
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(unfiltered_params, keys) ⇒ ParamsFilter
constructor
A new instance of ParamsFilter.
Constructor Details
#initialize(unfiltered_params, keys) ⇒ ParamsFilter
Returns a new instance of ParamsFilter.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/paraphrase/params_filter.rb', line 22 def initialize(unfiltered_params, keys) @params = unfiltered_params.with_indifferent_access.slice(*keys) @result = keys.inject(HashWithIndifferentAccess.new) do |result, key| value = respond_to?(key) ? send(key) : @params[key] value = scrub(value) if value.present? result[key] = value end result end end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
20 21 22 |
# File 'lib/paraphrase/params_filter.rb', line 20 def params @params end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
20 21 22 |
# File 'lib/paraphrase/params_filter.rb', line 20 def result @result end |