Class: Yes::Core::CommandHandling::EventPublisher::AggregateEventPublicationData
- Inherits:
-
Struct
- Object
- Struct
- Yes::Core::CommandHandling::EventPublisher::AggregateEventPublicationData
- Defined in:
- lib/yes/core/command_handling/event_publisher.rb
Overview
Value object containing aggregate data needed for event publication
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#revision ⇒ Object
Returns the value of attribute revision.
Class Method Summary collapse
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context
11 12 13 |
# File 'lib/yes/core/command_handling/event_publisher.rb', line 11 def context @context end |
#id ⇒ Object
Returns the value of attribute id
11 12 13 |
# File 'lib/yes/core/command_handling/event_publisher.rb', line 11 def id @id end |
#name ⇒ Object
Returns the value of attribute name
11 12 13 |
# File 'lib/yes/core/command_handling/event_publisher.rb', line 11 def name @name end |
#revision ⇒ Object
Returns the value of attribute 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 |