Sha256: 51edb611f3ded2374fba3ce465b008ea21b7d3b04357dbda6428cea8fb2b1de4

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::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2)
    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.1.0 lib/ar_transaction_changes.rb