Sha256: e32cc33e063dc4d5ccd237331c631444d27fed14d95693c6dd6f937bd73ffd19
Contents?: true
Size: 1.25 KB
Versions: 61
Compression:
Stored size: 1.25 KB
Contents
module SparkApi module Models module Dirty def changed? changed.any? end def changed changed_attributes.keys end def changes Hash[changed.map { |attr| [attr, attribute_change(attr)] }] end def previous_changes @previously_changed end # hash with changed attributes and their original values def changed_attributes @changed_attributes ||= {} end # hash with changed attributes and their new values def dirty_attributes changed.inject({}) { |h, k| h[k] = attributes[k.to_s]; h } end private def reset_dirty @previously_changed = changed_attributes @changed_attributes.clear end def attribute_changed?(attr) changed.include?(attr) end def attribute_change(attr) [changed_attributes[attr], @attributes[attr.to_s]] if attribute_changed?(attr) end def attribute_will_change!(attr) attr = attr.to_s begin value = @attributes[attr] value = value.duplicable? ? value.clone : value rescue TypeError, NoMethodError; end changed_attributes[attr] = value unless changed.include?(attr) end end end end
Version data entries
61 entries across 61 versions & 1 rubygems