class Paraphrase::ParamsFilter
{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 {Query.param param} class method.
Public Class Methods
new(params, keys)
click to toggle source
# File lib/paraphrase/params_filter.rb, line 20 def initialize(params, keys) @keys = keys @params = params end
Public Instance Methods
[](key)
click to toggle source
# File lib/paraphrase/params_filter.rb, line 37 def [](key) @params[key.to_sym] || @params[key.to_s] end
params()
click to toggle source
# File lib/paraphrase/params_filter.rb, line 41 def params self end
result()
click to toggle source
# 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
Private Instance Methods
scrub(value)
click to toggle source
# File lib/paraphrase/params_filter.rb, line 47 def scrub(value) case value when Array value.delete_if { |v| scrub(v).blank? } when Hash value.delete_if { |k, v| scrub(v).blank? } when String value.strip else value end end