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

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



11
12
13
# File 'lib/yes/core/command_handling/event_publisher.rb', line 11

def context
  @context
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



11
12
13
# File 'lib/yes/core/command_handling/event_publisher.rb', line 11

def id
  @id
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



11
12
13
# File 'lib/yes/core/command_handling/event_publisher.rb', line 11

def name
  @name
end

#revisionObject

Returns the value of attribute revision

Returns:

  • (Object)

    the current value of revision



11
12
13
# File 'lib/yes/core/command_handling/event_publisher.rb', line 11

def revision
  @revision
end

Class Method Details

.from_aggregate(aggregate) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yes/core/command_handling/event_publisher.rb', line 12

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