Class: Akasha::Changeset

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_idObject (readonly)

Returns the value of attribute aggregate_id


5
6
7
# File 'lib/akasha/changeset.rb', line 5

def aggregate_id
  @aggregate_id
end

#eventsObject (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.

Returns:

  • (Boolean)

20
21
22
# File 'lib/akasha/changeset.rb', line 20

def empty?
  @events.empty?
end