require "ar_transaction_changes/version"

module ArTransactionChanges
  if (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2) || ActiveRecord::VERSION::MAJOR > 4
    def _run_create_callbacks
      ret = super
      store_transaction_changed_attributes if ret != false
      ret
    end

    def _run_update_callbacks
      ret = super
      store_transaction_changed_attributes if ret != false
      ret
    end

    def _run_commit_callbacks
      super
    ensure
      @transaction_changed_attributes = nil
    end

    def _run_rollback_callbacks
      super
    ensure
      @transaction_changed_attributes = nil
    end
  else
    def run_callbacks(kind, *args)
      ret = super
      case kind.to_sym
      when :create, :update
        store_transaction_changed_attributes if ret != false
      when :commit, :rollback
        @transaction_changed_attributes = nil
      end

      ret
    end
  end

  def transaction_changed_attributes
    changed_attributes.merge(@transaction_changed_attributes || {})
  end

  private

  def store_transaction_changed_attributes
    @transaction_changed_attributes = transaction_changed_attributes
  end
end

require "ar_transaction_changes/version"

module ArTransactionChanges
  if (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2) || ActiveRecord::VERSION::MAJOR > 4
    def _run_create_callbacks
      ret = super
      store_transaction_changed_attributes if ret != false
      ret
    end

    def _run_update_callbacks
      ret = super
      store_transaction_changed_attributes if ret != false
      ret
    end

    def _run_commit_callbacks
      super
    ensure
      @transaction_changed_attributes = nil
    end

    def _run_rollback_callbacks
      super
    ensure
      @transaction_changed_attributes = nil
    end
  else
    def run_callbacks(kind)
      ret = super
      case kind.to_sym
      when :create, :update
        store_transaction_changed_attributes if ret != false
      when :commit, :rollback
        @transaction_changed_attributes = nil
      end

      ret
    end
  end

  def transaction_changed_attributes
    changed_attributes.merge(@transaction_changed_attributes || {})
  end

  private

  def store_transaction_changed_attributes
    @transaction_changed_attributes = transaction_changed_attributes
  end
end

--- 
+++ 
@@ -26,7 +26,7 @@
       @transaction_changed_attributes = nil
     end
   else
-    def run_callbacks(kind)
+    def run_callbacks(kind, *args)
       ret = super
       case kind.to_sym
       when :create, :update
Allow additional arguments to run_callbacks for rails 3.2

ActiveSupport::Callbacks#run_callbacks is defined as

    def run_callbacks(kind, *args, &block)

in rails 3.2, then the `*args` argument was removed in rails 4.0, so
ar_transaction_changes should allow these additional arguments to be passed
in.
