Class: TCB::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/tcb/record.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events_from:, events:, store:, registrations:) ⇒ Record

Returns a new instance of Record.



11
12
13
14
15
16
# File 'lib/tcb/record.rb', line 11

def initialize(events_from:, events:, store:, registrations:)
  @events_from = events_from
  @events = events
  @store = store
  @registrations = registrations
end

Class Method Details

.call(events_from:, events:, within:, store:, registrations:, &block) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
# 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)
    .call(within: within, &block)
end

Instance Method Details

#call(within:, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/tcb/record.rb', line 18

def call(within:, &block)
  if within
    within.transaction { execute(&block) }
  else
    execute(&block)
  end
end