Class: Aggregates::Auditor
- Inherits:
-
Object
- Object
- Aggregates::Auditor
- Defined in:
- lib/aggregates/auditor.rb
Overview
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.
Instance Attribute Summary collapse
-
#aggregate_id ⇒ Object
readonly
Returns the value of attribute aggregate_id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#commands ⇒ Object
Returns all commands for a given aggregate.
- #commands_processed_after(time) ⇒ Object
- #commands_processed_by(time) ⇒ Object
-
#events ⇒ Object
Returns all stored events for a given aggregate.
- #events_processed_after(time) ⇒ Object
- #events_processed_by(time) ⇒ Object
-
#initialize(type, aggregate_id) ⇒ Auditor
constructor
A new instance of Auditor.
-
#inspect_state_at(time) ⇒ Object
This method creates a new instance of the aggregate root and replays the events on the aggregate alone.
Constructor Details
#initialize(type, aggregate_id) ⇒ Auditor
9 10 11 12 |
# File 'lib/aggregates/auditor.rb', line 9 def initialize(type, aggregate_id) @type = type @aggregate_id = aggregate_id end |
Instance Attribute Details
#aggregate_id ⇒ Object (readonly)
Returns the value of attribute aggregate_id.
7 8 9 |
# File 'lib/aggregates/auditor.rb', line 7 def aggregate_id @aggregate_id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/aggregates/auditor.rb', line 7 def type @type end |
Instance Method Details
#commands ⇒ Object
Returns all commands for a given aggregate.
29 30 31 |
# File 'lib/aggregates/auditor.rb', line 29 def commands @commands ||= Configuration.storage_backend.load_commands_by_aggregate_id(@aggregate_id) end |
#commands_processed_after(time) ⇒ Object
41 42 43 |
# File 'lib/aggregates/auditor.rb', line 41 def commands_processed_after(time) commands.select { |event| event.created_at > time } end |
#commands_processed_by(time) ⇒ Object
37 38 39 |
# File 'lib/aggregates/auditor.rb', line 37 def commands_processed_by(time) commands.select { |event| event.created_at < time } end |
#events ⇒ Object
Returns all stored events for a given aggregate.
24 25 26 |
# File 'lib/aggregates/auditor.rb', line 24 def events @events ||= Configuration.storage_backend.load_events_by_aggregate_id(@aggregate_id) end |
#events_processed_after(time) ⇒ Object
45 46 47 |
# File 'lib/aggregates/auditor.rb', line 45 def events_processed_after(time) events.select { |event| event.created_at > time } end |
#events_processed_by(time) ⇒ Object
33 34 35 |
# File 'lib/aggregates/auditor.rb', line 33 def events_processed_by(time) events.select { |event| event.created_at < time } end |
#inspect_state_at(time) ⇒ Object
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.
17 18 19 20 21 |
# File 'lib/aggregates/auditor.rb', line 17 def inspect_state_at(time) aggregate = @type.new @aggregate_id, mutable: false aggregate.replay_history up_to: time aggregate end |