class Aggregates::AggregateRepository
Uses the storage backend to store load aggregates.
Public Class Methods
new(storage_backend)
click to toggle source
# File lib/aggregates/aggregate_repository.rb, line 8 def initialize(storage_backend) @storage_backend = storage_backend end
Public Instance Methods
load_aggregate(type, id, at: nil)
click to toggle source
# File lib/aggregates/aggregate_repository.rb, line 12 def load_aggregate(type, id, at: nil) event_stream = create_aggregate_event_stream(type, id) aggregate = type.new(id, event_stream) replay_events_on_aggregate(aggregate, event_stream, at) aggregate end
Private Instance Methods
create_aggregate_event_stream(type, id)
click to toggle source
# File lib/aggregates/aggregate_repository.rb, line 21 def create_aggregate_event_stream(type, id) EventStream.new(@storage_backend, type, id) end
replay_events_on_aggregate(aggregate, event_stream, at)
click to toggle source
# File lib/aggregates/aggregate_repository.rb, line 25 def replay_events_on_aggregate(aggregate, event_stream, at) events = event_stream.load_events ending_at: at events.each do |event| aggregate.process_event(event) end end