class Console::Output::Sensitive
Constants
- REDACT
Public Class Methods
new(output, **options)
click to toggle source
# File lib/console/output/sensitive.rb, line 26 def initialize(output, **options) @output = output end
Public Instance Methods
call(subject = nil, *arguments, sensitive: true, **options, &block)
click to toggle source
# File lib/console/output/sensitive.rb, line 102 def call(subject = nil, *arguments, sensitive: true, **options, &block) if sensitive if sensitive.respond_to?(:call) filter = sensitive elsif sensitive.is_a?(Hash) filter = Filter.new(sensitive) end subject = redact(subject, filter) arguments = redact_array(arguments, filter) end @output.call(subject, *arguments, **options) end
redact(argument, filter)
click to toggle source
# File lib/console/output/sensitive.rb, line 72 def redact(argument, filter) case argument when String if filter filter.call(argument) elsif redact?(argument) "[REDACTED]" else argument end when Array redact_array(argument, filter) when Hash redact_hash(argument, filter) else redact(argument.to_s, filter) end end
redact?(text)
click to toggle source
# File lib/console/output/sensitive.rb, line 56 def redact?(text) text.match?(REDACT) end
redact_array(array, filter)
click to toggle source
# File lib/console/output/sensitive.rb, line 66 def redact_array(array, filter) array.map do |value| redact(value, filter) end end
redact_hash(arguments, filter)
click to toggle source
# File lib/console/output/sensitive.rb, line 60 def redact_hash(arguments, filter) arguments.transform_values do |value| redact(value, filter) end end