Method: DataMapper::Transaction#within
- Defined in:
- lib/dm-transactions.rb
#within ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute a block within this Transaction.
No #begin, #commit or #rollback is performed in #within, but this Transaction will pushed on the per thread stack of transactions for each adapter it is associated with, and it will ensures that it will pop the Transaction away again after the block is finished.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/dm-transactions.rb', line 179 def within unless block_given? raise 'No block provided' end unless begin? raise "Illegal state for within: #{state}" end adapters = @adapters adapters.each_key do |adapter| adapter.push_transaction(self) end begin yield self ensure adapters.each_key do |adapter| adapter.pop_transaction end end end |