class FishTransactions::CallbacksStorage
Stores callbacks to be run on certain events (currently, commit-only or rollback-only)
Public Class Methods
new()
click to toggle source
Creates the storage empty
# File lib/fish_transactions/callbacks_storage.rb, line 9 def initialize @on_commit = [] @on_rollback = [] end
Public Instance Methods
committed!()
click to toggle source
Runs all callbacks asociated with commit event
# File lib/fish_transactions/callbacks_storage.rb, line 32 def committed! @on_commit.each do |callback| callback.call end clear end
rolledback!()
click to toggle source
Runs all callbacks asociated with rollback event
# 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)
click to toggle source
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
# 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
Private Instance Methods
clear()
click to toggle source
Clear callbacks
# File lib/fish_transactions/callbacks_storage.rb, line 52 def clear @on_commit.clear @on_rollback.clear end