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



20
21
22
23
24
25
26
27
28
# File 'lib/dynamoid/dirty.rb', line 20

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

#reloadObject



16
17
18
# File 'lib/dynamoid/dirty.rb', line 16

def reload
  super.tap { clear_changes }
end

#saveObject



12
13
14
# File 'lib/dynamoid/dirty.rb', line 12

def save(*)
  clear_changes { super }
end

#write_attribute(name, value) ⇒ Object



30
31
32
33
# File 'lib/dynamoid/dirty.rb', line 30

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