Class: FiberAudit::Runtime::Redactor
- Inherits:
-
Object
- Object
- FiberAudit::Runtime::Redactor
- Defined in:
- lib/fiber_audit/runtime/redactor.rb
Constant Summary collapse
- REDACTED =
'[redacted]'- EXTERNAL =
'[external]'- WINDOWS_ABSOLUTE =
%r{\A[A-Za-z]:/}
Instance Attribute Summary collapse
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root:, policy: Policy.new) ⇒ Redactor
constructor
A new instance of Redactor.
- #location(path:, line: nil, column: nil) ⇒ Object
- #operation(value) ⇒ Object
Constructor Details
#initialize(root:, policy: Policy.new) ⇒ Redactor
Returns a new instance of Redactor.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fiber_audit/runtime/redactor.rb', line 16 def initialize(root:, policy: Policy.new) raise RuntimeContractError, 'policy must be a FiberAudit::Runtime::Policy' unless policy.is_a?(Policy) safe_root = Validation.string(root, 'root', max_bytes: 4_096) @root = canonical_root(safe_root).freeze @policy = policy freeze rescue ArgumentError raise RuntimeContractError, 'root is invalid' end |
Instance Attribute Details
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
14 15 16 |
# File 'lib/fiber_audit/runtime/redactor.rb', line 14 def policy @policy end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
14 15 16 |
# File 'lib/fiber_audit/runtime/redactor.rb', line 14 def root @root end |
Instance Method Details
#location(path:, line: nil, column: nil) ⇒ Object
27 28 29 30 31 |
# File 'lib/fiber_audit/runtime/redactor.rb', line 27 def location(path:, line: nil, column: nil) Location.new(path: redact_path(path), line: line, column: column) rescue RuntimeContractError Location.new(path: REDACTED, line: nil, column: nil) end |
#operation(value) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fiber_audit/runtime/redactor.rb', line 33 def operation(value) return if value.nil? text = value.is_a?(String) || value.is_a?(Symbol) ? value.to_s : nil return REDACTED unless text&.valid_encoding? && text.bytesize <= 256 return REDACTED if text.match?(Validation::CONTROL) return REDACTED unless text.match?(Validation::OPERATION) text.dup.freeze end |