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:, correlation_id: nil, causation_id: nil) ⇒ Record
constructor
A new instance of Record.
Constructor Details
#initialize(events_from:, events:, store:, registrations:, correlation_id: nil, causation_id: nil) ⇒ Record
Returns a new instance of Record.
18 19 20 21 22 23 24 25 |
# File 'lib/tcb/record.rb', line 18 def initialize(events_from:, events:, store:, registrations:, correlation_id: nil, causation_id: nil) @events_from = events_from @events = events @store = store @registrations = registrations @correlation_id = correlation_id @causation_id = causation_id end |
Class Method Details
.call(events_from:, events:, within:, store:, registrations:, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/tcb/record.rb', line 5 def self.call(events_from:, events:, within:, store:, 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, 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
27 28 29 30 31 32 33 |
# File 'lib/tcb/record.rb', line 27 def call(within:, &block) if within.respond_to?(:transaction) within.transaction { execute(&block) } else execute(&block) end end |