Class: RailsSimpleEventSourcing::EventPlayer
- Inherits:
-
Object
- Object
- RailsSimpleEventSourcing::EventPlayer
- Defined in:
- lib/rails_simple_event_sourcing/event_player.rb
Instance Method Summary collapse
-
#initialize(aggregate) ⇒ EventPlayer
constructor
A new instance of EventPlayer.
- #replay_and_apply(new_event) ⇒ Object
- #replay_stream(up_to_version: nil) ⇒ Object
Constructor Details
#initialize(aggregate) ⇒ EventPlayer
Returns a new instance of EventPlayer.
5 6 7 |
# File 'lib/rails_simple_event_sourcing/event_player.rb', line 5 def initialize(aggregate) @aggregate = aggregate end |
Instance Method Details
#replay_and_apply(new_event) ⇒ Object
9 10 11 12 |
# File 'lib/rails_simple_event_sourcing/event_player.rb', line 9 def replay_and_apply(new_event) replay_stream unless @aggregate.new_record? new_event.apply(@aggregate) end |
#replay_stream(up_to_version: nil) ⇒ Object
14 15 16 17 |
# File 'lib/rails_simple_event_sourcing/event_player.rb', line 14 def replay_stream(up_to_version: nil) events = load_event_stream(up_to_version:) apply_events(events) end |