Module: Synapse::Domain::AggregateRoot
- Included in:
- EventSourcing::AggregateRoot
- Defined in:
- lib/synapse/domain/aggregate_root.rb
Overview
Mixin module for a basic aggregate root
Instance Attribute Summary collapse
-
#deleted ⇒ Boolean
(also: #deleted?)
readonly
True if this aggregate has been marked for deletion.
-
#id ⇒ Object
readonly
The identifier of this aggregate.
-
#version ⇒ Integer
readonly
The version of this aggregate.
Instance Method Summary collapse
-
#add_registration_listener(&listener) ⇒ undefined
Adds a listener that will be notified when this aggregate registers an event to be published.
-
#mark_committed ⇒ undefined
Marks this aggregate as committed by a repository.
-
#uncommitted_event_count ⇒ Integer
Returns the number of uncommitted events published by this aggregate.
-
#uncommitted_events ⇒ DomainEventStream
Returns a domain event strema containing any uncommitted events published by this aggregate.
Instance Attribute Details
#deleted ⇒ Boolean (readonly) Also known as: deleted?
Returns True if this aggregate has been marked for deletion.
6 7 8 |
# File 'lib/synapse/domain/aggregate_root.rb', line 6 def deleted @deleted end |
#id ⇒ Object (readonly)
Returns The identifier of this aggregate.
11 12 13 |
# File 'lib/synapse/domain/aggregate_root.rb', line 11 def id @id end |
#version ⇒ Integer (readonly)
Returns The version of this aggregate.
14 15 16 |
# File 'lib/synapse/domain/aggregate_root.rb', line 14 def version @version end |
Instance Method Details
#add_registration_listener(&listener) ⇒ undefined
Adds a listener that will be notified when this aggregate registers an event to be published
If an event registration listener is added after events have already been registered, it will still get a change to process the uncommitted events in this aggregate.
23 24 25 |
# File 'lib/synapse/domain/aggregate_root.rb', line 23 def add_registration_listener(&listener) event_container.add_registration_listener listener end |
#mark_committed ⇒ undefined
Marks this aggregate as committed by a repository
29 30 31 32 33 34 |
# File 'lib/synapse/domain/aggregate_root.rb', line 29 def mark_committed if @event_container @last_sequence_number = @event_container.last_sequence_number @event_container.mark_committed end end |
#uncommitted_event_count ⇒ Integer
Returns the number of uncommitted events published by this aggregate
38 39 40 41 42 43 44 |
# File 'lib/synapse/domain/aggregate_root.rb', line 38 def uncommitted_event_count unless @event_container return 0 end @event_container.size end |
#uncommitted_events ⇒ DomainEventStream
Returns a domain event strema containing any uncommitted events published by this aggregate
48 49 50 51 52 53 54 |
# File 'lib/synapse/domain/aggregate_root.rb', line 48 def uncommitted_events unless @event_container return SimpleDomainEventStream.new end @event_container.to_stream end |