Sha256: 8427fb86b87fb04a19cc60473f08529dc92f0983d6d10a34f6f01b545b1ddfbe

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

require "ar_transaction_changes/version"

module ArTransactionChanges
  create_or_update_suffix = ActiveRecord::VERSION::MAJOR <= 3 ? "" : "_record"

  define_method :"create#{create_or_update_suffix}" do |*args|
    super(*args).tap do |status|
      store_transaction_changed_attributes if status != false
    end
  end

  define_method :"update#{create_or_update_suffix}" do |*args|
    super(*args).tap do |status|
      store_transaction_changed_attributes if status != false
    end
  end

  def committed!(*)
    super
  ensure
    @transaction_changed_attributes = nil
  end

  def rolledback!(*)
    super
  ensure
    @transaction_changed_attributes = nil
  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

2 entries across 2 versions & 1 rubygems

Version Path
ar_transaction_changes-0.0.3 lib/ar_transaction_changes.rb
ar_transaction_changes-0.0.2 lib/ar_transaction_changes.rb