Class: Startback::Support::Redactor

Inherits:
Object
  • Object
show all
Defined in:
lib/startback/support/redactor.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{

  # Words used to stop dumping for, e.g., security reasons
  blacklist: "token password secret credential email address"

}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Redactor

Returns a new instance of Redactor.



12
13
14
# File 'lib/startback/support/redactor.rb', line 12

def initialize(options = {})
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Method Details

#redact(data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/startback/support/redactor.rb', line 16

def redact(data)
  case data
  when Hash, OpenStruct
    Hash[data.map{|(k,v)|
      [k, (k.to_s =~ blacklist_rx) ? '---redacted---' : redact(v)]
    }]
  when Enumerable
    data.map{|elm| redact(elm) }.compact
  when /:\/\//
    data.gsub(/:\/\/([^@]+[@])/){|m| "://--redacted--@" }
  else
    data
  end
end