Class: Hubbado::Trailblazer::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/hubbado/trailblazer/transaction.rb

Class Method Summary collapse

Class Method Details

.call(_ctx, _flow_options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/hubbado/trailblazer/transaction.rb', line 4

def self.call((_ctx, _flow_options), *)
  res = nil

  if defined?(ActiveRecord)
    ActiveRecord::Base.transaction do
      res = yield
      raise ActiveRecord::Rollback if res.first.to_h[:semantic] == :failure
    end
  else
    # No transaction support available
    res = yield
  end

  res
end