Sha256: 89810b066b0cd1835488ce0741a927f8c92a063257635e23e32534645bd54bd4

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require "ar_transaction_changes/version"

module ArTransactionChanges
  if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2 && ActiveRecord::VERSION::TINY != 3
    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar_transaction_changes-1.0.2 lib/ar_transaction_changes.rb