Class: Julewire::Redaction::StringRedactor
- Inherits:
-
Object
- Object
- Julewire::Redaction::StringRedactor
- Defined in:
- lib/julewire/redaction/string_redactor.rb
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(matcher:, mask:, authorization_header: true) ⇒ StringRedactor
constructor
A new instance of StringRedactor.
Constructor Details
#initialize(matcher:, mask:, authorization_header: true) ⇒ StringRedactor
Returns a new instance of StringRedactor.
6 7 8 9 10 11 12 |
# File 'lib/julewire/redaction/string_redactor.rb', line 6 def initialize(matcher:, mask:, authorization_header: true) @matcher = matcher @mask = mask.to_s @authorization_header = @redact_headers = @authorization_header || !@matcher.empty? @redact_pairs = !@matcher.empty? end |
Instance Method Details
#call(value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/julewire/redaction/string_redactor.rb', line 14 def call(value) return value unless value.is_a?(String) has_colon = value.include?(":") has_equals = value.include?("=") return value unless redaction_possible?(has_colon, has_equals) redacted = value.dup redact_header_lines!(redacted) if header_redaction_possible?(has_colon) return redacted unless @redact_pairs return redacted unless @matcher.string_key_possible?(value) redact_json_pairs!(redacted) if json_pair_possible?(value, has_colon) redact_form_pairs!(redacted) if form_pair_possible?(has_equals) redacted end |