Class: FlightControl::ArgumentsFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/flight_control/arguments_filter.rb

Overview

Replaces argument values with [FILTERED] for any keys that match a filter.

Constant Summary collapse

FILTERED =
"[FILTERED]"

Instance Method Summary collapse

Constructor Details

#initialize(filter) ⇒ ArgumentsFilter

Returns a new instance of ArgumentsFilter.



5
6
7
# File 'lib/flight_control/arguments_filter.rb', line 5

def initialize(filter)
  @filter = filter
end

Instance Method Details

#apply_to(arguments) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/flight_control/arguments_filter.rb', line 9

def apply_to(arguments)
  case arguments
  when Array
    arguments.map { |a| apply_to(a) }
  when Hash
    arguments.map do |k, v|
      [k, filter.include?(k.to_s) ? FILTERED : v]
    end.to_h
  else
    arguments
  end
end