Class: Granite::Action::TransactionManager::TransactionsStack
- Inherits:
-
Object
- Object
- Granite::Action::TransactionManager::TransactionsStack
- Defined in:
- lib/granite/action/transaction_manager/transactions_stack.rb
Overview
A class to manage transaction callbacks stack.
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
Instance Method Summary collapse
- #add_callback(callback) ⇒ Object
- #callbacks ⇒ Object
-
#initialize ⇒ TransactionsStack
constructor
A new instance of TransactionsStack.
- #transaction ⇒ Object
Constructor Details
#initialize ⇒ TransactionsStack
Returns a new instance of TransactionsStack.
8 9 10 11 |
# File 'lib/granite/action/transaction_manager/transactions_stack.rb', line 8 def initialize @callbacks = [] @depth = 0 end |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
6 7 8 |
# File 'lib/granite/action/transaction_manager/transactions_stack.rb', line 6 def depth @depth end |
Instance Method Details
#add_callback(callback) ⇒ Object
23 24 25 26 27 |
# File 'lib/granite/action/transaction_manager/transactions_stack.rb', line 23 def add_callback(callback) fail 'Start a transaction before you add callbacks on it' if depth.zero? @callbacks.last << callback end |
#callbacks ⇒ Object
29 30 31 |
# File 'lib/granite/action/transaction_manager/transactions_stack.rb', line 29 def callbacks @callbacks.flatten end |
#transaction ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/granite/action/transaction_manager/transactions_stack.rb', line 13 def transaction start_new! result = yield finish_current! result rescue StandardError, ScriptError rollback_current! raise end |