Module: Rufus::Tokyo::Transactions

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

Public Visibility

Public Instance Method Summary

#abort

Aborts the enclosing transaction.

#transaction

Transaction in a block.

Public Instance Method Details

abort

public abort

Aborts the enclosing transaction

See #transaction

Meta Tags

Raises:

[Abort]
[View source]


70
71
72
# File 'lib/rufus/tokyo/transactions.rb', line 70

def abort
  raise Abort, "abort transaction !"
end

transaction

public 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.

[View source]


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rufus/tokyo/transactions.rb', line 49

def transaction

  return unless block_given?

  begin
    tranbegin
    yield
    trancommit
  rescue Rufus::Tokyo::Transactions::Abort
    tranabort
  rescue Exception => e
    tranabort
    raise e
  end
end
Generated on Friday, September 18 2009 at 10:35:42 AM by YARD 0.2.3.5 (ruby-1.8.7).