Module: Philiprehberger::AuditTrail::Replayable
- Included in:
- Tracker
- Defined in:
- lib/philiprehberger/audit_trail/replayable.rb
Overview
Reconstructs entity state by replaying recorded events in chronological order.
Instance Method Summary collapse
-
#replay(entity_id:, entity_type: nil, until_time: nil) ⇒ Hash
Replay events for an entity to rebuild its current (or point-in-time) state.
Instance Method Details
#replay(entity_id:, entity_type: nil, until_time: nil) ⇒ Hash
Replay events for an entity to rebuild its current (or point-in-time) state.
Walks recorded events oldest-first and folds each ‘:changes` hash into a state accumulator. `:create` and `:update` actions write `:to` values; `:delete` clears the field. Other actions are skipped.
17 18 19 20 21 |
# File 'lib/philiprehberger/audit_trail/replayable.rb', line 17 def replay(entity_id:, entity_type: nil, until_time: nil) events_for_replay(entity_id, entity_type, until_time).each_with_object({}) do |event, state| apply_event(state, event) end end |