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 =
Default replacement used by mask rules.
"[REDACTED]"- POLICY_METADATA_KEY =
Payload metadata key containing the applied policy fingerprint.
"mammoth_payload_policy"- SUPPORTED_ACTIONS =
Transformation actions accepted by payload-policy rules.
%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.
25 26 27 28 29 |
# File 'lib/mammoth/payload_policy.rb', line 25 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.
22 23 24 |
# File 'lib/mammoth/payload_policy.rb', line 22 def config @config end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
22 23 24 |
# File 'lib/mammoth/payload_policy.rb', line 22 def fingerprint @fingerprint end |
Instance Method Details
#active? ⇒ Boolean
Returns whether the policy contains transformation rules.
32 33 34 |
# File 'lib/mammoth/payload_policy.rb', line 32 def active? rules.any? end |
#apply(payload) ⇒ Hash
Transform one canonical event or transaction payload.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mammoth/payload_policy.rb', line 40 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 |