Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Sep 14, 2012
1 parent 58ced30 commit dd48f0e
Showing 1 changed file with 8 additions and 4 deletions.
Expand Up @@ -180,14 +180,14 @@ def transaction(options = {})


begin begin
if @transaction.closed? || requires_new if @transaction.closed? || requires_new
@transaction = @transaction.begin begin_transaction
transaction_open = true transaction_open = true
end end


yield yield
rescue Exception => error rescue Exception => error
if !outside_transaction? && transaction_open if !outside_transaction? && transaction_open
@transaction = @transaction.rollback rollback_transaction
transaction_open = false transaction_open = false
end end


Expand All @@ -201,9 +201,9 @@ def transaction(options = {})
@transaction = Transactions::Closed.new(self) @transaction = Transactions::Closed.new(self)
elsif @transaction.open? && transaction_open elsif @transaction.open? && transaction_open
begin begin
@transaction = @transaction.commit commit_transaction
rescue Exception rescue Exception
@transaction = @transaction.rollback rollback_transaction
raise raise
end end
end end
Expand All @@ -217,6 +217,10 @@ def begin_transaction #:nodoc:
@transaction = @transaction.begin @transaction = @transaction.begin
end end


def commit_transaction #:nodoc:
@transaction = @transaction.commit
end

def rollback_transaction #:nodoc: def rollback_transaction #:nodoc:
@transaction = @transaction.rollback @transaction = @transaction.rollback
end end
Expand Down

0 comments on commit dd48f0e

Please sign in to comment.