Class: Devise::ParameterFilter
- Inherits:
-
Object
- Object
- Devise::ParameterFilter
- Defined in:
- lib/devise/parameter_filter.rb
Instance Method Summary collapse
- #filter(conditions) ⇒ Object
- #filtered_hash_by_method_for_given_keys(conditions, method, condition_keys) ⇒ Object
-
#initialize(case_insensitive_keys, strip_whitespace_keys) ⇒ ParameterFilter
constructor
A new instance of ParameterFilter.
-
#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) ⇒ ParameterFilter
Returns a new instance of ParameterFilter.
5 6 7 8 |
# File 'lib/devise/parameter_filter.rb', line 5 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
10 11 12 13 14 15 16 17 |
# File 'lib/devise/parameter_filter.rb', line 10 def filter(conditions) conditions = stringify_params(conditions.dup) conditions.merge!(filtered_hash_by_method_for_given_keys(conditions.dup, :downcase, @case_insensitive_keys)) conditions.merge!(filtered_hash_by_method_for_given_keys(conditions.dup, :strip, @strip_whitespace_keys)) conditions end |
#filtered_hash_by_method_for_given_keys(conditions, method, condition_keys) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/devise/parameter_filter.rb', line 19 def filtered_hash_by_method_for_given_keys(conditions, method, condition_keys) condition_keys.each do |k| value = conditions[k] conditions[k] = value.send(method) if value.respond_to?(method) end conditions end |
#stringify_params(conditions) ⇒ Object
Force keys to be string to avoid injection on mongoid related database.
29 30 31 32 33 34 |
# File 'lib/devise/parameter_filter.rb', line 29 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 |