class Akasha::Changeset

Represents changes to an aggregate, for example an array of events generated when handling a command.

Attributes

aggregate_id[R]
events[R]

Public Class Methods

new(aggregate_id) click to toggle source
# File lib/akasha/changeset.rb, line 7
def initialize(aggregate_id)
  @aggregate_id = aggregate_id
  @events = []
end

Public Instance Methods

append(event_name, **data) click to toggle source

Adds an event to the changeset.

# 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!() click to toggle source

Clears the changeset.

# File lib/akasha/changeset.rb, line 25
def clear!
  @events = []
end
empty?() click to toggle source

Returns true if no changes recorded.

# File lib/akasha/changeset.rb, line 20
def empty?
  @events.empty?
end