Class: TCB::Record
- Inherits:
-
Object
- Object
- TCB::Record
- Defined in:
- lib/tcb/record.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(within:, &block) ⇒ Object
-
#initialize(events_from:, events:, store:, registrations:, outbox_registrations: [], correlation_id: nil, causation_id: nil) ⇒ Record
constructor
A new instance of Record.
Constructor Details
#initialize(events_from:, events:, store:, registrations:, outbox_registrations: [], correlation_id: nil, causation_id: nil) ⇒ Record
Returns a new instance of Record.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tcb/record.rb', line 21 def initialize( events_from:, events:, store:, registrations:, outbox_registrations: [], correlation_id: nil, causation_id: nil ) @events_from = events_from @events = events @store = store @registrations = registrations @outbox_registrations = outbox_registrations @correlation_id = correlation_id @causation_id = causation_id end |
Class Method Details
.call(events_from:, events:, within:, store:, registrations:, outbox_registrations: [], &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tcb/record.rb', line 5 def self.call( events_from:, events:, within:, store:, registrations:, outbox_registrations: [], &block ) raise ArgumentError, "events_from: or events: must be provided" if events_from.empty? && events.empty? new( events_from: events_from, events: events, store: store, registrations: registrations, outbox_registrations: outbox_registrations, correlation_id: Thread.current[:tcb_correlation_id], causation_id: Thread.current[:tcb_causation_id] ).call(within: within, &block) end |
Instance Method Details
#call(within:, &block) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/tcb/record.rb', line 34 def call(within:, &block) if within.respond_to?(:transaction) within.transaction { execute(&block) } else execute(&block) end end |