module FishTransactions::ActiveRecordMods::Base
Modifications for ActiveRecord::Base class All methods here will be class level methods
Public Class Methods
extended( base )
click to toggle source
When extended, this module will:
-
alias the
:transaction
method and them override it
# File lib/fish_transactions/active_record_mods/base.rb, line 17 def self.extended( base ) base.class_eval do class << self # create an alias for the original +transaction+ method alias_method :original_ar_transaction, :transaction # and we 'rename' the new method as transaction alias_method :transaction, :transaction_with_callbacks end end end
Public Instance Methods
callbacks()
click to toggle source
read-access to callbacks storage
# File lib/fish_transactions/active_record_mods/base.rb, line 61 def callbacks connection.fish_callbacks_storage ||= FishTransactions::CallbacksStorage.new end
transaction_with_callbacks(*args) { || ... }
click to toggle source
Wrapper of original transaction. Captures and then raises Rollback exception to know there were a rollback
# File lib/fish_transactions/active_record_mods/base.rb, line 36 def transaction_with_callbacks(*args) committed = true original_ar_transaction(*args) do begin yield rescue ActiveRecord::Rollback committed = false raise end end rescue Exception committed = false raise ensure if committed callbacks.committed! else callbacks.rolledback! end end