Class: Yes::Core::TransactionDetails
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Yes::Core::TransactionDetails
- Defined in:
- lib/yes/core/transaction_details.rb
Overview
Value object representing a command transaction’s context.
Carries correlation/causation IDs for event sourcing traceability, caller identity, and OpenTelemetry trace context.
Class Method Summary collapse
-
.from_event(event) ⇒ TransactionDetails
Creates TransactionDetails from an existing event.
Instance Method Summary collapse
-
#for_eventstore_metadata ⇒ Hash
Returns metadata formatted for the event store.
-
#to_h ⇒ Hash
Compact hash representation.
Class Method Details
.from_event(event) ⇒ TransactionDetails
Creates TransactionDetails from an existing event.
81 82 83 84 85 86 87 |
# File 'lib/yes/core/transaction_details.rb', line 81 def self.from_event(event) new( correlation_id: event.['$correlationId'].presence || SecureRandom.uuid, causation_id: event.id, otl_contexts: event.['otl_contexts'] ) end |
Instance Method Details
#for_eventstore_metadata ⇒ Hash
Returns metadata formatted for the event store.
65 66 67 68 69 70 |
# File 'lib/yes/core/transaction_details.rb', line 65 def to_h.slice(:correlation_id, :causation_id, :otl_contexts).tap do |h| h[:$correlationId] = h.delete(:correlation_id) h[:$causationId] = h.delete(:causation_id) end end |
#to_h ⇒ Hash
Returns compact hash representation.
73 74 75 |
# File 'lib/yes/core/transaction_details.rb', line 73 def to_h super.compact end |