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 Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(params, keys) ⇒ ParamsFilter
constructor
A new instance of ParamsFilter.
- #params ⇒ Object
- #result ⇒ Object
Constructor Details
#initialize(params, keys) ⇒ ParamsFilter
Returns a new instance of ParamsFilter.
20 21 22 23 |
# File 'lib/paraphrase/params_filter.rb', line 20 def initialize(params, keys) @keys = keys @params = params end |
Instance Method Details
#[](key) ⇒ Object
37 38 39 |
# File 'lib/paraphrase/params_filter.rb', line 37 def [](key) @params[key.to_sym] || @params[key.to_s] end |
#params ⇒ Object
41 42 43 |
# File 'lib/paraphrase/params_filter.rb', line 41 def params self end |
#result ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/paraphrase/params_filter.rb', line 25 def result @keys.inject(ActiveSupport::HashWithIndifferentAccess.new) do |result, key| value = scrub(public_send(key)) if value.present? result[key] = value end result end end |