Class: Yes::Core::CommandHandling::EventPublisher::AggregateEventPublicationData

Inherits:
Struct
  • Object
show all
Defined in:
lib/yes/core/command_handling/event_publisher.rb

Overview

Value object containing aggregate data needed for event publication

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#context ⇒ Object

Returns the value of attribute context

Returns:

  • (Object) —

    the current value of context



18
19
20
# File 'lib/yes/core/command_handling/event_publisher.rb', line 18

def context
  @context
end

#id ⇒ Object

Returns the value of attribute id

Returns:

  • (Object) —

    the current value of id



18
19
20
# File 'lib/yes/core/command_handling/event_publisher.rb', line 18

def id
  @id
end

#name ⇒ Object

Returns the value of attribute name

Returns:

  • (Object) —

    the current value of name



18
19
20
# File 'lib/yes/core/command_handling/event_publisher.rb', line 18

def name
  @name
end

#revision ⇒ Object

Returns the value of attribute revision

Returns:

  • (Object) —

    the current value of revision



18
19
20
# File 'lib/yes/core/command_handling/event_publisher.rb', line 18

def revision
  @revision
end

Class Method Details

.from_aggregate(aggregate) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/yes/core/command_handling/event_publisher.rb', line 19

def self.from_aggregate(aggregate)
  new(
    id: aggregate.id,
    context: aggregate.class.context,
    name: aggregate.class.name.split('::')[1],
    revision: lambda {
      if aggregate.class.read_model_enabled?
        aggregate.reload.revision
      else
        # When read models are disabled, get revision directly from event stream
        begin
          latest = aggregate.latest_event
          latest ? latest.stream_revision : -1
        rescue PgEventstore::StreamNotFoundError
          # Stream doesn't exist yet - this is the first event
          -1
        end
      end
    }
  )
end