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

Instance Method Summary collapse

Instance Attribute Details

#deletedBoolean (readonly) Also known as: deleted?

Returns True if this aggregate has been marked for deletion.

Returns:

  • (Boolean)

    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

#idObject (readonly)

Returns The identifier of this aggregate.

Returns:

  • (Object)

    The identifier of this aggregate



11
12
13
# File 'lib/synapse/domain/aggregate_root.rb', line 11

def id
  @id
end

#versionInteger (readonly)

Returns The version of this aggregate.

Returns:

  • (Integer)

    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.

Parameters:

  • listener (#call)

Returns:

  • (undefined)


52
53
54
# File 'lib/synapse/domain/aggregate_root.rb', line 52

def add_registration_listener(&listener)
  event_container.add_registration_listener listener
end

#mark_committedundefined

Marks this aggregate as committed by a repository

Returns:

  • (undefined)


18
19
20
21
22
23
# File 'lib/synapse/domain/aggregate_root.rb', line 18

def mark_committed
  if @event_container
    @last_sequence_number = @event_container.last_sequence_number
    @event_container.mark_committed
  end
end

#uncommitted_event_countInteger

Returns the number of uncommitted events published by this aggregate

Returns:

  • (Integer)


27
28
29
30
31
32
33
# File 'lib/synapse/domain/aggregate_root.rb', line 27

def uncommitted_event_count
  unless @event_container
    return 0
  end

  @event_container.size
end

#uncommitted_eventsDomainEventStream

Returns a domain event strema containing any uncommitted events published by this aggregate

Returns:



37
38
39
40
41
42
43
# File 'lib/synapse/domain/aggregate_root.rb', line 37

def uncommitted_events
  unless @event_container
    return SimpleDomainEventStream.new
  end

  @event_container.to_stream
end