module MongoMapper::Plugins::PartialUpdates
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/mongo_mapper/plugins/partial_updates.rb, line 16 def initialize(*) _reset_partial_updates_callback super end
Public Instance Methods
fields_for_partial_update()
click to toggle source
# File lib/mongo_mapper/plugins/partial_updates.rb, line 21 def fields_for_partial_update raise PartialUpdatesDisabledError if !partial_updates Hash.new.tap do |hash| attrs = _dealiased_attributes hash[:set_fields] = Array.new.tap do |array| attrs.each do |key, value| if !@_last_saved_attributes.include?(key) || @_last_saved_attributes[key] != value array << key end end end hash[:unset_fields] = @_last_saved_attributes.keys - attrs.keys end end
Private Instance Methods
_dealiased_attributes()
click to toggle source
# File lib/mongo_mapper/plugins/partial_updates.rb, line 77 def _dealiased_attributes self.class.dealias_keys(attributes) end
_reset_attributes_for_partial_update()
click to toggle source
# File lib/mongo_mapper/plugins/partial_updates.rb, line 81 def _reset_attributes_for_partial_update @_last_saved_attributes = _dealiased_attributes._mongo_mapper_deep_copy_ end
_reset_partial_updates_callback()
click to toggle source
# File lib/mongo_mapper/plugins/partial_updates.rb, line 42 def _reset_partial_updates_callback _reset_attributes_for_partial_update if partial_updates true end
save_to_collection(options={})
click to toggle source
Calls superclass method
# File lib/mongo_mapper/plugins/partial_updates.rb, line 55 def save_to_collection(options={}) if partial_updates && options[:persistence_method] == :update updates = fields_for_partial_update set_fields = updates[:set_fields] unset_fields = updates[:unset_fields] if set_fields.any? || unset_fields.any? set_fields.push("_id") if !set_fields.include?("_id") end options = options.merge({ :set_fields => set_fields, :unset_fields => unset_fields }) super(options) else super end end
update(options={})
click to toggle source
Calls superclass method
# File lib/mongo_mapper/plugins/partial_updates.rb, line 47 def update(options={}) if partial_updates super(options.merge(:persistence_method => :update)) else super end end