Module: DatastaxRails::AttributeMethods::Dirty
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Dirty
- Defined in:
- lib/datastax_rails/attribute_methods/dirty.rb
Instance Method Summary collapse
-
#reload ⇒ Object
reload
the record and clears changed attributes. -
#save ⇒ Object
Attempts to
save
the record and clears changed attributes if successful. -
#save! ⇒ Object
Attempts to
save!
the record and clears changed attributes if successful. - #write_attribute(attr, value) ⇒ Object
Instance Method Details
#reload ⇒ Object
reload
the record and clears changed attributes.
37 38 39 40 41 42 |
# File 'lib/datastax_rails/attribute_methods/dirty.rb', line 37 def reload(*) super.tap do @previously_changed.clear @changed_attributes.clear end end |
#save ⇒ Object
Attempts to save
the record and clears changed attributes if successful.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/datastax_rails/attribute_methods/dirty.rb', line 14 def save(*) #:nodoc: if (status = super) # FIXME: This dup/replace mess is here to work around what APPEARS to be a bug in Rails # See Issue #29 for details attrs = @attributes.dup @previously_changed = changes @attributes = attrs @changed_attributes.clear end status end |
#save! ⇒ Object
Attempts to save!
the record and clears changed attributes if successful.
27 28 29 30 31 32 33 34 |
# File 'lib/datastax_rails/attribute_methods/dirty.rb', line 27 def save!(*) #:nodoc: super.tap do attrs = @attributes.dup @previously_changed = changes @attributes = attrs @changed_attributes.clear end end |
#write_attribute(attr, value) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/datastax_rails/attribute_methods/dirty.rb', line 44 def write_attribute(attr, value) attr = attr.to_s loaded_attributes[attr] = true # The attribute already has an unsaved change. if attribute_changed?(attr) old = @changed_attributes[attr] @changed_attributes.delete(attr) unless _field_changed?(attr, old, value) else old = clone_attribute_value(:read_attribute, attr) @changed_attributes[attr] = old if _field_changed?(attr, old, value) end super end |