Class: Akasha::Changeset
- Inherits:
-
Object
- Object
- Akasha::Changeset
- Defined in:
- lib/akasha/changeset.rb
Overview
Represents changes to an aggregate, for example an array of events generated when handling a command.
Instance Attribute Summary collapse
-
#aggregate_id ⇒ Object
readonly
Returns the value of attribute aggregate_id.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
-
#append(event_name, **data) ⇒ Object
Adds an event to the changeset.
-
#clear! ⇒ Object
Clears the changeset.
-
#empty? ⇒ Boolean
Returns true if no changes recorded.
-
#initialize(aggregate_id) ⇒ Changeset
constructor
A new instance of Changeset.
Constructor Details
#initialize(aggregate_id) ⇒ Changeset
Returns a new instance of Changeset.
7 8 9 10 |
# File 'lib/akasha/changeset.rb', line 7 def initialize(aggregate_id) @aggregate_id = aggregate_id @events = [] end |
Instance Attribute Details
#aggregate_id ⇒ Object (readonly)
Returns the value of attribute aggregate_id.
5 6 7 |
# File 'lib/akasha/changeset.rb', line 5 def aggregate_id @aggregate_id end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
5 6 7 |
# File 'lib/akasha/changeset.rb', line 5 def events @events end |
Instance Method Details
#append(event_name, **data) ⇒ Object
Adds an event to the changeset.
13 14 15 16 17 |
# File 'lib/akasha/changeset.rb', line 13 def append(event_name, **data) id = SecureRandom.uuid event = Akasha::Event.new(event_name, id, { aggregate_id: @aggregate_id }, **data) @events << event end |
#clear! ⇒ Object
Clears the changeset.
25 26 27 |
# File 'lib/akasha/changeset.rb', line 25 def clear! @events = [] end |
#empty? ⇒ Boolean
Returns true if no changes recorded.
20 21 22 |
# File 'lib/akasha/changeset.rb', line 20 def empty? @events.empty? end |