class Negroni::ParamFilter

ParamFilter is responsible for filtering blacklisted parameters from a request for validation and authentication.

Public Class Methods

new(case_insensitive_keys, strip_whitespace_keys) click to toggle source

Creates a new instance of `ParamFilter`.

@param case_insensitive_keys [Array<Symbol>] keys which are not case

sensitive

@param strip_whitespace_keys [Array<Symbol>] keys which should have

whitespace stripped
# File lib/negroni/param_filter.rb, line 14
def initialize(case_insensitive_keys, strip_whitespace_keys)
  @case_insensitive_keys = case_insensitive_keys || []
  @strip_whitespace_keys = strip_whitespace_keys || []
end

Public Instance Methods

filter(conditions) click to toggle source

Filter the `conditions` based on case_insensitive_keys and

\@strip_whitespace_keys.

@param conditions [Hash] the conditions hash to filter

@return [Hash] the filtered `conditions` hash

# File lib/negroni/param_filter.rb, line 25
def filter(conditions)
  conditions = stringify_params(conditions.dup.to_h)

  conditions.merge! filtered_hash_by_meth_for_keys(conditions.dup,
                                                   :downcase,
                                                   @case_insensitive_keys)

  conditions.merge! filtered_hash_by_meth_for_keys(conditions.dup,
                                                   :strip,
                                                   @strip_whitespace_keys)
end

Private Instance Methods

filtered_hash_by_meth_for_keys(conditions, method, condition_keys) click to toggle source
# File lib/negroni/param_filter.rb, line 39
def filtered_hash_by_meth_for_keys(conditions, method, condition_keys)
  condition_keys.each do |key|
    value = conditions[key]
    conditions[key] = value.send(method) if value.respond_to?(method)
  end

  conditions
end
stringify_params(conditions) click to toggle source
# File lib/negroni/param_filter.rb, line 48
def stringify_params(conditions)
  return conditions unless conditions.is_a? Hash
  conditions.each { |k, v| conditions[k] = v.to_s }
end