Module: Kiev::ParamFilter

Defined in:
lib/kiev/param_filter.rb

Constant Summary collapse

FILTERED =
"[FILTERED]"

Class Method Summary collapse

Class Method Details

.filter(params, filtered_params, ignored_params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kiev/param_filter.rb', line 7

def self.filter(params, filtered_params, ignored_params)
  params.each_with_object({}) do |(key, value), acc|
    next if ignored_params.include?(key)

    if defined?(ActionDispatch) && value.is_a?(ActionDispatch::Http::UploadedFile)
      value = {
        original_filename: value.original_filename,
        content_type: value.content_type,
        headers: value.headers
      }
    end

    acc[key] =
      if filtered_params.include?(key) && !value.is_a?(Hash)
        FILTERED
      elsif value.is_a?(Hash)
        filter(value, filtered_params, ignored_params)
      else
        value
      end
  end
end