Class: Console::Output::Sensitive
- Defined in:
 - lib/console/output/sensitive.rb
 
Defined Under Namespace
Classes: Filter
Constant Summary collapse
- REDACT =
 / phone | email | full_?name | first_?name | last_?name | device_name | user_agent | zip | address | location | latitude | longitude | ip | gps | sex | gender | token | password /xi
Instance Method Summary collapse
- #call(subject = nil, *arguments, sensitive: true, **options, &block) ⇒ Object
 - 
  
    
      #initialize(output, redact: REDACT, **options)  ⇒ Sensitive 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Sensitive.
 - #redact(argument, filter) ⇒ Object
 - #redact?(text) ⇒ Boolean
 - #redact_array(array, filter) ⇒ Object
 - #redact_hash(arguments, filter) ⇒ Object
 
Methods inherited from Wrapper
Constructor Details
Instance Method Details
#call(subject = nil, *arguments, sensitive: true, **options, &block) ⇒ Object
      89 90 91 92 93 94 95 96 97 98 99 100 101 102  | 
    
      # File 'lib/console/output/sensitive.rb', line 89 def call(subject = nil, *arguments, sensitive: true, **, &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 super(subject, *arguments, **) end  | 
  
#redact(argument, filter) ⇒ Object
      59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76  | 
    
      # File 'lib/console/output/sensitive.rb', line 59 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) ⇒ Boolean
      43 44 45  | 
    
      # File 'lib/console/output/sensitive.rb', line 43 def redact?(text) text.match?(@redact) end  | 
  
#redact_array(array, filter) ⇒ Object
      53 54 55 56 57  | 
    
      # File 'lib/console/output/sensitive.rb', line 53 def redact_array(array, filter) array.map do |value| redact(value, filter) end end  | 
  
#redact_hash(arguments, filter) ⇒ Object
      47 48 49 50 51  | 
    
      # File 'lib/console/output/sensitive.rb', line 47 def redact_hash(arguments, filter) arguments.transform_values do |value| redact(value, filter) end end  |