Class: Revise::ParamFilter
- Inherits:
-
Object
- Object
- Revise::ParamFilter
- Defined in:
- lib/revise/param_filter.rb
Instance Method Summary collapse
- #filter(conditions) ⇒ Object
-
#initialize(case_insensitive_keys, strip_whitespace_keys) ⇒ ParamFilter
constructor
A new instance of ParamFilter.
-
#stringify_params(conditions) ⇒ Object
Force keys to be string to avoid injection on mongoid related database.
Constructor Details
#initialize(case_insensitive_keys, strip_whitespace_keys) ⇒ ParamFilter
Returns a new instance of ParamFilter.
3 4 5 6 |
# File 'lib/revise/param_filter.rb', line 3 def initialize(case_insensitive_keys, strip_whitespace_keys) @case_insensitive_keys = case_insensitive_keys || [] @strip_whitespace_keys = strip_whitespace_keys || [] end |
Instance Method Details
#filter(conditions) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/revise/param_filter.rb', line 8 def filter(conditions) conditions = stringify_params(conditions.dup) @case_insensitive_keys.each do |k| value = conditions[k] next unless value.respond_to?(:downcase) conditions[k] = value.downcase end @strip_whitespace_keys.each do |k| value = conditions[k] next unless value.respond_to?(:strip) conditions[k] = value.strip end conditions end |
#stringify_params(conditions) ⇒ Object
Force keys to be string to avoid injection on mongoid related database.
27 28 29 30 31 32 |
# File 'lib/revise/param_filter.rb', line 27 def stringify_params(conditions) return conditions unless conditions.is_a?(Hash) conditions.each do |k, v| conditions[k] = v.to_s if param_requires_string_conversion?(v) end end |