Class: FishTransactions::CallbacksStorage
- Inherits:
-
Object
- Object
- FishTransactions::CallbacksStorage
- Defined in:
- lib/fish_transactions/callbacks_storage.rb
Overview
Stores callbacks to be run on certain events (currently, commit-only or rollback-only)
Instance Method Summary collapse
-
#committed! ⇒ Object
Runs all callbacks asociated with commit event.
-
#initialize ⇒ CallbacksStorage
constructor
Creates the storage empty.
-
#rolledback! ⇒ Object
Runs all callbacks asociated with rollback event.
-
#store(event, &callback_block) ⇒ Object
Stores a callback block to run on a event.
Constructor Details
#initialize ⇒ CallbacksStorage
Creates the storage empty
9 10 11 12 |
# File 'lib/fish_transactions/callbacks_storage.rb', line 9 def initialize @on_commit = [] @on_rollback = [] end |
Instance Method Details
#committed! ⇒ Object
Runs all callbacks asociated with commit event
32 33 34 35 36 37 |
# File 'lib/fish_transactions/callbacks_storage.rb', line 32 def committed! @on_commit.each do |callback| callback.call end clear end |
#rolledback! ⇒ Object
Runs all callbacks asociated with rollback event
41 42 43 44 45 46 |
# File 'lib/fish_transactions/callbacks_storage.rb', line 41 def rolledback! @on_rollback.each do |callback| callback.call end clear end |
#store(event, &callback_block) ⇒ Object
Stores a callback block to run on a event
An event must be one of these symbols:
-
:commit
- run callback on commit only -
:rollback
- run callback on rollback only -
otherwise will raise an exception
22 23 24 25 26 27 28 |
# File 'lib/fish_transactions/callbacks_storage.rb', line 22 def store(event,&callback_block) case event when :commit then @on_commit << callback_block when :rollback then @on_rollback << callback_block else raise "unknown event #{event.inspect}" end end |