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
# File 'lib/akasha/changeset.rb', line 13

def append(event_name, **data)
  @events << Akasha::Event.new(event_name, **data)
end

#clear!Object

Clears the changeset.



23
24
25
# File 'lib/akasha/changeset.rb', line 23

def clear!
  @events = []
end

#empty?Boolean

Returns true if no changes recorded.

Returns:

  • (Boolean)


18
19
20
# File 'lib/akasha/changeset.rb', line 18

def empty?
  @events.empty?
end