Module: Mongoid::Dirty
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Dirty
- Included in:
- Components
- Defined in:
- lib/mongoid/dirty.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#changes ⇒ Hash
Get the changed values for the document.
-
#move_changes ⇒ Object
Call this method after save, so the changes can be properly switched.
-
#remove_change(name) ⇒ Object
Remove a change from the dirty attributes hash.
-
#setters ⇒ Hash
Gets all the new values for each of the changed fields, to be passed to a MongoDB $set modifier.
Instance Method Details
#changes ⇒ Hash
This is overriding the AM::Dirty implementation to handle enumerable fields being in the hash when not actually changed.
Get the changed values for the document. This is a hash with the name of the field as the keys, and the values being an array of previous and current pairs.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mongoid/dirty.rb', line 20 def changes {}.tap do |hash| changed.each do |name| change = attribute_change(name) if change hash[name] = change if change[0] != change[1] end end end end |
#move_changes ⇒ Object
Call this method after save, so the changes can be properly switched.
This will unset the memoized children array, set new record to false, set the document as validated, and move the dirty changes.
40 41 42 43 44 45 46 47 |
# File 'lib/mongoid/dirty.rb', line 40 def move_changes @_children = nil @previously_changed = changes atomic_pulls.clear atomic_unsets.clear delayed_atomic_sets.clear changed_attributes.clear end |
#remove_change(name) ⇒ Object
Remove a change from the dirty attributes hash. Used by the single field atomic updators.
58 59 60 |
# File 'lib/mongoid/dirty.rb', line 58 def remove_change(name) changed_attributes.delete(name.to_s) end |
#setters ⇒ Hash
Gets all the new values for each of the changed fields, to be passed to a MongoDB $set modifier.
71 72 73 74 75 76 77 78 |
# File 'lib/mongoid/dirty.rb', line 71 def setters {}.tap do |modifications| changes.each_pair do |field, changes| key = ? "#{atomic_position}.#{field}" : field modifications[key] = changes[1] end end end |