Module: Granite::Action::TransactionManager
- Defined in:
- lib/granite/action/transaction_manager.rb,
lib/granite/action/transaction_manager/transactions_stack.rb
Overview
:nodoc:
Defined Under Namespace
Classes: TransactionsStack
Class Method Summary collapse
-
.after_commit(listener = nil, &block) ⇒ Object
Adds a block or listener object to be executed after finishing the current transaction.
-
.transaction(&block) ⇒ Object
Runs a block in a transaction It will open a new transaction or append a block to the current one if it exists.
Class Method Details
.after_commit(listener = nil, &block) ⇒ Object
Adds a block or listener object to be executed after finishing the current transaction. Callbacks are reset after each transaction.
23 24 25 26 27 28 29 |
# File 'lib/granite/action/transaction_manager.rb', line 23 def after_commit(listener = nil, &block) callback = listener || block raise 'Block or object is required to register after_commit hook!' unless callback transactions_stack.add_callback callback end |
.transaction(&block) ⇒ Object
Runs a block in a transaction It will open a new transaction or append a block to the current one if it exists
13 14 15 16 17 |
# File 'lib/granite/action/transaction_manager.rb', line 13 def transaction(&block) run_in_transaction(&block) || false ensure finish_root_transaction if transactions_stack.depth.zero? end |