Class: Negroni::ParamFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/negroni/param_filter.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(case_insensitive_keys, strip_whitespace_keys) ⇒ ParamFilter

Creates a new instance of ‘ParamFilter`.

Parameters:

  • case_insensitive_keys (Array<Symbol>)

    keys which are not case sensitive

  • strip_whitespace_keys (Array<Symbol>)

    keys which should have whitespace stripped



14
15
16
17
# 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

Instance Method Details

#filter(conditions) ⇒ Hash

Filter the ‘conditions` based on @case_insensitive_keys and

\@strip_whitespace_keys.

Parameters:

  • conditions (Hash)

    the conditions hash to filter

Returns:

  • (Hash)

    the filtered ‘conditions` hash



25
26
27
28
29
30
31
32
33
34
35
# 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