Class: DataMapper::Resource::PersistenceState::Dirty

Inherits:
Persisted show all
Defined in:
lib/dm-core/resource/persistence_state/dirty.rb

Overview

a persisted/dirty resource

Instance Attribute Summary

Attributes inherited from DataMapper::Resource::PersistenceState

#resource

Instance Method Summary collapse

Methods inherited from Persisted

#get

Methods inherited from DataMapper::Resource::PersistenceState

#get, #initialize

Methods included from Equalizer

#equalize

Constructor Details

This class inherits a constructor from DataMapper::Resource::PersistenceState

Instance Method Details

#commitObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dm-core/resource/persistence_state/dirty.rb', line 18

def commit
  remove_from_identity_map
  set_child_keys
  return self unless valid_attributes?
  update_resource
  reset_original_attributes
  reset_resource_key
  Clean.new(resource)
ensure
  add_to_identity_map
end

#deleteObject



13
14
15
16
# File 'lib/dm-core/resource/persistence_state/dirty.rb', line 13

def delete
  reset_resource
  Deleted.new(resource)
end

#original_attributesObject



35
36
37
# File 'lib/dm-core/resource/persistence_state/dirty.rb', line 35

def original_attributes
  @original_attributes ||= {}
end

#rollbackObject



30
31
32
33
# File 'lib/dm-core/resource/persistence_state/dirty.rb', line 30

def rollback
  reset_resource
  Clean.new(resource)
end

#set(subject, value) ⇒ Object



7
8
9
10
11
# File 'lib/dm-core/resource/persistence_state/dirty.rb', line 7

def set(subject, value)
  track(subject, value)
  super
  original_attributes.empty? ? Clean.new(resource) : self
end