Sha256: 2f6c47a192baba47393d2e1db0edefeedcc98bce20d91a239e513a3ce1828aa5
Contents?: true
Size: 990 Bytes
Versions: 12
Compression:
Stored size: 990 Bytes
Contents
module MotionPrime module ModelDirtyMixin extend ::MotionSupport::Concern def self.included(base) base.class_attribute :_changed_attributes end def track_changed_attributes(&block) @_changed_attributes ||= {} old_attrs = self.info.clone result = block.call new_attrs = self.info.clone new_bags = self._bags.clone new_attrs.each do |key, value| if value != old_attrs[key] && !@_changed_attributes.has_key?(key.to_s) @_changed_attributes[key.to_s] = old_attrs[key] end end new_bags.each do |key, value| if value.key != old_attrs[key] && !@_changed_attributes.has_key?(key.to_s) @_changed_attributes[key.to_s] = old_attrs[key] end end result end def has_changed?(key = nil) @_changed_attributes ||= {} if key @_changed_attributes.has_key?(key.to_s) else @_changed_attributes.present? end end end end
Version data entries
12 entries across 12 versions & 1 rubygems