class ActiveSupport::ParameterFilter
> reverses the value to all keys matching /secret/i
end])
v.reverse! if k =~ /secret/i
ActiveSupport::ParameterFilter.new([-> (k, v) do
change { file: { code: “xxxx”} }
=> replaces { credit_card: {code: “xxxx”} } with “[FILTERED]”, does not<br>ActiveSupport::ParameterFilter.new()
=> replaces the value to all keys matching /foo|bar/i with “[FILTERED]”
ActiveSupport::ParameterFilter.new([:foo, “bar”])
=> replaces the value to all keys matching /password/i with “[FILTERED]”<br>ActiveSupport::ParameterFilter.new()
using String#replace or similar methods.
all sub-hashes are passed to it, where the value or the key can be replaced
’credit_card.number’. If a proc is given, each key and value of a hash and
sub-keys from a hash is possible by using the dot notation:
hash-like object and replace corresponding value. Filtering only certain
ParameterFilter
allows you to specify keys for sensitive data from¶ ↑
def compiled_filter
def compiled_filter @compiled_filter ||= CompiledFilter.compile(@filters, mask: @mask) end
def filter(params)
def filter(params) compiled_filter.call(params) end
def filter_param(key, value)
def filter_param(key, value) @filters.empty? ? value : compiled_filter.value_for_key(key, value) end
def initialize(filters = [], mask: FILTERED)
==== Options
For +Proc+ filters, key, value, and optional original hash is passed to block arguments.
Other types of filters are treated as +String+ using +to_s+.
Create instance with given filters. Supported type of filters are +String+, +Regexp+, and +Proc+.
def initialize(filters = [], mask: FILTERED) @filters = filters @mask = mask end