From 90f41eb586340d6552663189cbab82d26eda5f9f Mon Sep 17 00:00:00 2001 From: Zoxc Date: Fri, 8 Jul 2011 19:36:18 +0200 Subject: [PATCH] Always commit or rollback an transaction. Previous code only handled Ruby exceptions correctly. --- lib/dm-transactions.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/dm-transactions.rb b/lib/dm-transactions.rb index 57f4d05..a5a7874 100644 --- a/lib/dm-transactions.rb +++ b/lib/dm-transactions.rb @@ -129,19 +129,13 @@ def commit begin self.begin rval = within { |*block_args| yield(*block_args) } - rescue Exception => exception - if begin? - rollback - end - raise exception + commit + complete = true ensure - unless exception - if begin? - commit - end - return rval - end + rollback unless complete end + + rval else unless begin? raise "Illegal state for commit without block: #{state}"