lib/grumlin/traversal_start.rb in grumlin-0.21.1 vs lib/grumlin/traversal_start.rb in grumlin-0.22.0
- old
+ new
@@ -3,22 +3,40 @@
module Grumlin
class TraversalStart < Steppable
include WithExtension
class TraversalError < Grumlin::Error; end
- class AlreadyBoundToTransationError < TraversalError; end
+ class AlreadyBoundToTransactionError < TraversalError; end
def tx
- raise AlreadyBoundToTransationError if @session_id
+ raise AlreadyBoundToTransactionError if @session_id
- Transaction.new(self.class, pool: @pool)
+ transaction = tx_class.new(self.class, pool: @pool)
+ return transaction unless block_given?
+
+ begin
+ yield transaction.begin
+ rescue Grumlin::Rollback
+ transaction.rollback
+ rescue StandardError
+ transaction.rollback
+ raise
+ else
+ transaction.commit
+ end
end
def to_s(*)
self.class.to_s
end
def inspect
self.class.inspect
+ end
+
+ private
+
+ def tx_class
+ Grumlin.features.supports_transactions? ? Transaction : DummyTransaction
end
end
end