class Aggregates::Auditor
The Auditor
captures the state of a given aggregate at time of use. It provides listings of the commands and events that we executed on a given aggregate.
Attributes
aggregate_id[R]
type[R]
Public Class Methods
new(storage_backend, type, aggregate_id)
click to toggle source
# File lib/aggregates/auditor.rb, line 9 def initialize(storage_backend, type, aggregate_id) @storage_backend = storage_backend @type = type @aggregate_id = aggregate_id end
Public Instance Methods
commands()
click to toggle source
Returns all commands for a given aggregate.
# File lib/aggregates/auditor.rb, line 29 def commands @commands ||= @storage_backend.load_commands_by_aggregate_id(@aggregate_id) end
commands_processed_after(time)
click to toggle source
# File lib/aggregates/auditor.rb, line 41 def commands_processed_after(time) commands.select { |event| event.created_at > time } end
commands_processed_by(time)
click to toggle source
# File lib/aggregates/auditor.rb, line 37 def commands_processed_by(time) commands.select { |event| event.created_at < time } end
events()
click to toggle source
Returns all stored events for a given aggregate.
# File lib/aggregates/auditor.rb, line 24 def events @events ||= @storage_backend.load_events_by_aggregate_id(@aggregate_id) end
events_processed_after(time)
click to toggle source
# File lib/aggregates/auditor.rb, line 45 def events_processed_after(time) events.select { |event| event.created_at > time } end
events_processed_by(time)
click to toggle source
# File lib/aggregates/auditor.rb, line 33 def events_processed_by(time) events.select { |event| event.created_at < time } end
inspect_state_at(time)
click to toggle source
This method creates a new instance of the aggregate root and replays the events on the aggregate alone. Only events that happened prior to the time specified are processed.
# File lib/aggregates/auditor.rb, line 18 def inspect_state_at(time) aggregate_repository = AggregateRepository.new(@storage_backend) aggregate_repository.load_aggregate(@type, @aggregate_id, at: time) end