Module: DatastaxRails::AttributeMethods::Dirty

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Dirty
Defined in:
lib/datastax_rails/attribute_methods/dirty.rb

Instance Method Summary collapse

Instance Method Details

#reloadObject

reload the record and clears changed attributes.



31
32
33
34
35
36
# File 'lib/datastax_rails/attribute_methods/dirty.rb', line 31

def reload(*)
  super.tap do
    @previously_changed.clear
    @changed_attributes.clear
  end
end

#saveObject

Attempts to save the record and clears changed attributes if successful.



14
15
16
17
18
19
20
# File 'lib/datastax_rails/attribute_methods/dirty.rb', line 14

def save(*) #:nodoc:
  if (status = super)
    @previously_changed = changes
    @changed_attributes.clear
  end
  status
end

#save!Object

Attempts to save! the record and clears changed attributes if successful.



23
24
25
26
27
28
# File 'lib/datastax_rails/attribute_methods/dirty.rb', line 23

def save!(*) #:nodoc:
  super.tap do
    @previously_changed = changes
    @changed_attributes.clear
  end
end

#write_attribute(attr, value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/datastax_rails/attribute_methods/dirty.rb', line 38

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