Module: Dynamoid::Dirty

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Dirty
Included in:
Components
Defined in:
lib/dynamoid/dirty.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#clear_changesObject



28
29
30
31
32
33
34
35
36
# File 'lib/dynamoid/dirty.rb', line 28

def clear_changes
  previous = changes
  (block_given? ? yield : true).tap do |result|
    unless result == false # failed validation; nil is OK.
      @previously_changed = previous
      clear_changes_information
    end
  end
end

#reloadObject



24
25
26
# File 'lib/dynamoid/dirty.rb', line 24

def reload
  super.tap { clear_changes }
end

#saveObject



14
15
16
# File 'lib/dynamoid/dirty.rb', line 14

def save(*)
  clear_changes { super }
end

#update!Object



18
19
20
21
22
# File 'lib/dynamoid/dirty.rb', line 18

def update!(*)
  ret = super
  clear_changes # update! completely reloads all fields on the class, so any extant changes are wiped out
  ret
end

#write_attribute(name, value) ⇒ Object



38
39
40
41
# File 'lib/dynamoid/dirty.rb', line 38

def write_attribute(name, value)
  attribute_will_change!(name) unless read_attribute(name) == value
  super
end