Sha256: 1da97e58f6ffd554964dac6572b266358d0675c8a90abbc9bfb3edf42d52c95a

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar_transaction_changes-1.0.1 lib/ar_transaction_changes.rb