Class: RailsSimpleEventSourcing::EventPlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_simple_event_sourcing/event_player.rb

Instance Method Summary collapse

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