Class: Tracebook::RedactionRule
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Tracebook::RedactionRule
- Defined in:
- app/models/tracebook/redaction_rule.rb
Overview
Rule for redacting PII from interaction payloads.
Defines a regex pattern to detect and replace sensitive data before persistence. Runs on request, response, or both payloads.
Fields
name- Human-readable name for this rulepattern- Regular expression pattern to matchreplacement- Replacement string (e.g., "[REDACTED]", "[EMAIL]")applies_to- Where to apply::request,:response,:both,:metadataenabled- Whether this rule is active
Built-in Rules
TraceBook includes default redactors for:
- Email addresses
- Phone numbers (US format)
- Credit card PANs
Instance Attribute Summary collapse
-
#applies_to ⇒ Symbol
Where to apply redaction (:request, :response, :both, :metadata).
Instance Method Summary collapse
-
#compiled_pattern ⇒ Regexp
Returns the compiled regex pattern.
Instance Attribute Details
#applies_to ⇒ Symbol
Returns Where to apply redaction (:request, :response, :both, :metadata).
57 |
# File 'app/models/tracebook/redaction_rule.rb', line 57 enum :applies_to, { request: 0, response: 1, both: 2, metadata: 3 } |
Instance Method Details
#compiled_pattern ⇒ Regexp
Returns the compiled regex pattern.
Caches the compiled pattern for performance. If pattern is invalid, falls back to escaped literal match.
73 74 75 76 77 |
# File 'app/models/tracebook/redaction_rule.rb', line 73 def compiled_pattern @compiled_pattern ||= Regexp.new(pattern, Regexp::MULTILINE) rescue RegexpError Regexp.new(Regexp.escape(pattern.to_s)) end |