Class: Whodunit::Chronicles::LedgerEntry
- Inherits:
-
Data
- Object
- Data
- Whodunit::Chronicles::LedgerEntry
- Defined in:
- lib/whodunit/chronicles/ledger_entry.rb,
sig/whodunit/chronicles/ledger_entry.rbs
Overview
Immutable audit-domain representation of one CDC::Core::ChangeEvent.
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#entity ⇒ String
readonly
Returns the value of attribute entity.
-
#event_id ⇒ String
readonly
Returns the value of attribute event_id.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#metadata ⇒ Hash[untyped, untyped]
readonly
Returns the value of attribute metadata.
-
#namespace ⇒ String
readonly
Returns the value of attribute namespace.
-
#occurred_at ⇒ Object
readonly
Returns the value of attribute occurred_at.
-
#operation ⇒ Symbol
readonly
Returns the value of attribute operation.
-
#payload ⇒ Hash[untyped, untyped]
readonly
Returns the value of attribute payload.
-
#recorded_at ⇒ Object
readonly
Returns the value of attribute recorded_at.
Class Method Summary collapse
-
.from_change_event(event, clock: Time) ⇒ LedgerEntry
(also: from_event)
Build a ledger entry from a normalized CDC change event.
- .new ⇒ Object
Instance Method Summary collapse
- #initialize ⇒ Object constructor
- #members ⇒ Array[Symbol]
-
#ordering_identity ⇒ String
Build a stable ordering identity for per-record ordering.
-
#to_h ⇒ Hash<Symbol, Object>
Convert this entry to a Hash keyed by attribute name.
Constructor Details
#initialize ⇒ Object
16 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 16
def initialize: (
|
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
11 12 13 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 11 def actor @actor end |
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
12 13 14 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 12 def changes @changes end |
#entity ⇒ String (readonly)
Returns the value of attribute entity.
8 9 10 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 8 def entity @entity end |
#event_id ⇒ String (readonly)
Returns the value of attribute event_id.
4 5 6 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 4 def event_id @event_id end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
9 10 11 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 9 def identity @identity end |
#metadata ⇒ Hash[untyped, untyped] (readonly)
Returns the value of attribute metadata.
13 14 15 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 13 def @metadata end |
#namespace ⇒ String (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 7 def namespace @namespace end |
#occurred_at ⇒ Object (readonly)
Returns the value of attribute occurred_at.
5 6 7 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 5 def occurred_at @occurred_at end |
#operation ⇒ Symbol (readonly)
Returns the value of attribute operation.
10 11 12 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 10 def operation @operation end |
#payload ⇒ Hash[untyped, untyped] (readonly)
Returns the value of attribute payload.
14 15 16 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 14 def payload @payload end |
#recorded_at ⇒ Object (readonly)
Returns the value of attribute recorded_at.
6 7 8 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 6 def recorded_at @recorded_at end |
Class Method Details
.from_change_event(event, clock: Time) ⇒ LedgerEntry Also known as: from_event
Build a ledger entry from a normalized CDC change event.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/whodunit/chronicles/ledger_entry.rb', line 27 def self.from_change_event(event, clock: Time) validate_change_event!(event) new( event_id: event_id_for(event), occurred_at: event.occurred_at || clock.now, recorded_at: clock.now, namespace: namespace_for(event), entity: entity_for(event), identity: event.primary_key, operation: event.operation, actor: actor_for(event), changes: changes_for(event), metadata: (event), payload: event.to_h ) end |
.new ⇒ Object
30 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 30
def self.new: (
|
Instance Method Details
#members ⇒ Array[Symbol]
48 |
# File 'sig/whodunit/chronicles/ledger_entry.rbs', line 48
def members: () -> Array[Symbol]
|
#ordering_identity ⇒ String
Build a stable ordering identity for per-record ordering.
59 60 61 |
# File 'lib/whodunit/chronicles/ledger_entry.rb', line 59 def ordering_identity [namespace, entity, identity].compact.join(':') end |
#to_h ⇒ Hash<Symbol, Object>
Convert this entry to a Hash keyed by attribute name.
52 53 54 |
# File 'lib/whodunit/chronicles/ledger_entry.rb', line 52 def to_h members.to_h { |name| [name, public_send(name)] } end |