Module: Rufus::Tokyo::Transactions
- Included in:
- Edo::CabinetCore, Edo::TableCore, Cabinet, Table
- Defined in:
- lib/rufus/tokyo/transactions.rb
Overview
A mixin for structures to respond to tranbegin, trancommit and tranabort
Instance Method Summary collapse
-
#abort ⇒ Object
Aborts the enclosing transaction.
-
#transaction ⇒ Object
Transaction in a block.
Instance Method Details
#abort ⇒ Object
Aborts the enclosing transaction
See #transaction
67 68 69 |
# File 'lib/rufus/tokyo/transactions.rb', line 67 def abort raise "abort transaction !" end |
#transaction ⇒ Object
Transaction in a block.
table.transaction do
table['pk0'] => { 'name' => 'Fred', 'age' => '40' }
table['pk1'] => { 'name' => 'Brooke', 'age' => '76' }
table.abort if weather.bad?
end
(This is a table example, a classical cabinet won’t accept a hash as a value for its entries).
If an error or an abort is trigger withing the transaction, it’s rolled back. If the block executes successfully, it gets commited.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rufus/tokyo/transactions.rb', line 49 def transaction return unless block_given? begin tranbegin yield trancommit rescue Exception => e tranabort end end |