Class: Startback::Support::Redactor
- Inherits:
-
Object
- Object
- Startback::Support::Redactor
- 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
-
#initialize(options = {}) ⇒ Redactor
constructor
A new instance of Redactor.
- #redact(data) ⇒ Object
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 = DEFAULT_OPTIONS.merge() 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 |