Module: RDF::Transactable
- Included in:
- Graph, Repository
- Defined in:
- lib/rdf/mixin/transactable.rb
Overview
A transaction application mixin.
Classes that include this module must provide a ‘#begin_transaction` method returning an Transaction.
Instance Method Summary collapse
-
#transaction(mutable: false, &block) ⇒ Object
(also: #transact)
Executes the given block in a transaction.
Instance Method Details
#transaction(mutable: false) ⇒ RDF::Transaction #transaction(mutable: false) {|tx| ... } ⇒ self Also known as: transact
Executes the given block in a transaction.
Raising an error within the transaction block causes automatic rollback.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rdf/mixin/transactable.rb', line 50 def transaction(mutable: false, &block) tx = begin_transaction(mutable: mutable) return tx unless block_given? begin case block.arity when 1 then block.call(tx) else tx.instance_eval(&block) end rescue => error rollback_transaction(tx) raise error end commit_transaction(tx) self end |