Class: ActsAsMentionable::TransactionCallbacks
- Inherits:
-
Object
- Object
- ActsAsMentionable::TransactionCallbacks
- Defined in:
- lib/acts_as_mentionable/transaction_callbacks.rb
Instance Attribute Summary collapse
-
#on_committed_block ⇒ Object
readonly
Returns the value of attribute on_committed_block.
-
#on_rolled_back_block ⇒ Object
readonly
Returns the value of attribute on_rolled_back_block.
Class Method Summary collapse
Instance Method Summary collapse
- #committed!(_should_run_callbacks = true) ⇒ Object
-
#initialize(on_committed_block, on_rolled_back_block) ⇒ TransactionCallbacks
constructor
A new instance of TransactionCallbacks.
- #rolledback!(_force_restore_state = false, _should_run_callbacks = true) ⇒ Object
Constructor Details
#initialize(on_committed_block, on_rolled_back_block) ⇒ TransactionCallbacks
Returns a new instance of TransactionCallbacks.
29 30 31 32 |
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 29 def initialize on_committed_block, on_rolled_back_block @on_committed_block = on_committed_block @on_rolled_back_block = on_rolled_back_block end |
Instance Attribute Details
#on_committed_block ⇒ Object (readonly)
Returns the value of attribute on_committed_block.
27 28 29 |
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 27 def on_committed_block @on_committed_block end |
#on_rolled_back_block ⇒ Object (readonly)
Returns the value of attribute on_rolled_back_block.
27 28 29 |
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 27 def on_rolled_back_block @on_rolled_back_block end |
Class Method Details
.on_committed(&block) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 4 def on_committed &block if current_transaction.open? add_transaction_record new(block, nil) else yield end end |
.on_rolled_back(&block) ⇒ Object
12 13 14 |
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 12 def on_rolled_back &block add_transaction_record new(nil, block) end |
Instance Method Details
#committed!(_should_run_callbacks = true) ⇒ Object
34 35 36 |
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 34 def committed! _should_run_callbacks = true on_committed_block&.call end |
#rolledback!(_force_restore_state = false, _should_run_callbacks = true) ⇒ Object
38 39 40 |
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 38 def rolledback! _force_restore_state = false, _should_run_callbacks = true on_rolled_back_block&.call end |