6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/event_sourcing/aggregate/actor.rb', line 6
def self.for(aggregate)
Class.new(Concurrent::Actor::RestartingContext) do
define_method :initialize do |event_bus, event_stream|
@aggregate = aggregate.new(event_stream)
@event_bus = event_bus
@event_stream = event_stream
end
def on_message(message) if @aggregate.respond_to?(message.first)
events = @aggregate.send(*message) @event_stream.append(events) @event_bus.publish(events)
@aggregate._apply(events)
end
end
end
end
|