Sha256: 213f9683b193866c749d30ed5da550515cf6947ef9891e69bb98e4e6366d5846
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
require "ar_transaction_changes/version" require "active_record" module ArTransactionChanges def _run_commit_callbacks super ensure @transaction_changed_attributes = nil end def _run_rollback_callbacks super ensure @transaction_changed_attributes = nil end def transaction_changed_attributes @transaction_changed_attributes ||= HashWithIndifferentAccess.new end def _write_attribute(attr_name, value) _store_transaction_changed_attributes(attr_name) do super(attr_name, value) end end if ActiveRecord.version >= Gem::Version.new('6.1.0.alpha') def write_attribute(attr_name, value) _store_transaction_changed_attributes(attr_name) do super(attr_name, value) end end end private def _store_transaction_changed_attributes(attr_name) attr_name = attr_name.to_s old_value = read_attribute(attr_name) ret = yield new_value = read_attribute(attr_name) unless transaction_changed_attributes.key?(attr_name) || new_value == old_value transaction_changed_attributes[attr_name] = old_value end ret end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ar_transaction_changes-1.1.6 | lib/ar_transaction_changes.rb |