Class: Whodunit::Chronicles::LedgerEntry
- Inherits:
-
Object
- Object
- Whodunit::Chronicles::LedgerEntry
- Defined in:
- lib/whodunit/chronicles/ledger_entry.rb
Overview
Immutable audit-domain representation of one CDC::Core::ChangeEvent.
Class Method Summary collapse
-
.from_change_event(event, clock: Time) ⇒ LedgerEntry
(also: from_event)
Build a ledger entry from a normalized CDC change event.
Instance Method Summary collapse
-
#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.
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 |
Instance Method Details
#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 |