Module: MongoModel::AttributeMethods::Dirty

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Dirty
Included in:
EmbeddedDocument
Defined in:
lib/mongomodel/concerns/attribute_methods/dirty.rb

Instance Method Summary collapse

Instance Method Details

#original_attributesObject

Returns the attributes as they were before any changes were made to the document.



29
30
31
# File 'lib/mongomodel/concerns/attribute_methods/dirty.rb', line 29

def original_attributes
  {}.with_indifferent_access.merge(attributes).merge(changed_attributes)
end

#write_attribute(key, value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mongomodel/concerns/attribute_methods/dirty.rb', line 13

def write_attribute(key, value)
  attr = key.to_sym
  
  # The attribute already has an unsaved change.
  if changed_attributes.include?(attr)
    old = changed_attributes[attr]
    changed_attributes.delete(attr) if value == old
  else
    old = clone_attribute_value(attr)
    changed_attributes[attr] = old unless value == old
  end
  
  super
end