Class: Mammoth::PayloadPolicy
- Inherits:
-
Object
- Object
- Mammoth::PayloadPolicy
- Defined in:
- lib/mammoth/payload_policy.rb
Overview
Applies deterministic destination-scoped projection and redaction rules.
Policies operate on serialized Mammoth payloads, never on CDC-core work items. Column rules scrub every canonical row-value representation: data, identity, and old/new values in changes.
Constant Summary collapse
- DEFAULT_MASK =
"[REDACTED]"- POLICY_METADATA_KEY =
"mammoth_payload_policy"- SUPPORTED_ACTIONS =
%w[remove mask].freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Whether the policy contains transformation rules.
-
#apply(payload) ⇒ Hash
Transform one canonical event or transaction payload.
-
#initialize(config = nil) ⇒ PayloadPolicy
constructor
A new instance of PayloadPolicy.
Constructor Details
#initialize(config = nil) ⇒ PayloadPolicy
Returns a new instance of PayloadPolicy.
20 21 22 23 24 |
# File 'lib/mammoth/payload_policy.rb', line 20 def initialize(config = nil) @config = deep_freeze(stringify_keys(config || {})) validate! @fingerprint = build_fingerprint if active? end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/mammoth/payload_policy.rb', line 17 def config @config end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
17 18 19 |
# File 'lib/mammoth/payload_policy.rb', line 17 def fingerprint @fingerprint end |
Instance Method Details
#active? ⇒ Boolean
Returns whether the policy contains transformation rules.
27 28 29 |
# File 'lib/mammoth/payload_policy.rb', line 27 def active? rules.any? end |
#apply(payload) ⇒ Hash
Transform one canonical event or transaction payload.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mammoth/payload_policy.rb', line 35 def apply(payload) return payload unless active? transformed = JSON.parse(JSON.generate(payload)) events_for(transformed).each { |event| apply_rules(event) } = transformed["metadata"] = {} unless .is_a?(Hash) # steep:ignore transformed["metadata"] = [POLICY_METADATA_KEY] = { "fingerprint" => fingerprint } transformed end |