Sha256: bdd55445225abf08e66dd764d53288e38b6de6d7bb036e77c51dd9d6d336e447
Contents?: true
Size: 1013 Bytes
Versions: 15
Compression:
Stored size: 1013 Bytes
Contents
module Superstore module AttributeMethods module Dirty extend ActiveSupport::Concern include ActiveModel::Dirty # Attempts to +save+ the record and clears changed attributes if successful. def save(*) #:nodoc: if status = super @previously_changed = changes @changed_attributes = {} end status end # <tt>reload</tt> the record and clears changed attributes. def reload super.tap do @previously_changed.try :clear @changed_attributes.try :clear end end def unapplied_changes result = {} changed_attributes.each_key { |attr| result[attr] = read_attribute(attr) } result end def write_attribute(name, value) name = name.to_s old = read_attribute(name) super unless attribute_changed?(name) || old == read_attribute(name) changed_attributes[name] = old end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems