Module Rufus::Tokyo::Transactions

  1. lib/rufus/tokyo/transactions.rb

A mixin for structures to respond to tranbegin, trancommit and tranabort

Methods

public instance

  1. abort
  2. transaction

Public instance methods

abort ()

Aborts the enclosing transaction

See transaction

[show source]
    # File lib/rufus/tokyo/transactions.rb, line 67
67:     def abort
68:       raise "abort transaction !"
69:     end
transaction () {|| ...}

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.

[show source]
    # File lib/rufus/tokyo/transactions.rb, line 49
49:     def transaction
50: 
51:       return unless block_given?
52: 
53:       begin
54:         tranbegin
55:         yield
56:         trancommit
57:       rescue Exception => e
58:         tranabort
59:       end
60:     end