Class: Mongoid::Persistence::Atomic::Sets

Inherits:
Object
  • Object
show all
Includes:
Operation
Defined in:
lib/mongoid/persistence/atomic/sets.rb

Overview

This class provides atomic $set behaviour.

Instance Attribute Summary

Attributes included from Operation

#document, #field, #options, #value

Instance Method Summary collapse

Methods included from Operation

#collection, #initialize, #operation, #path, #prepare

Instance Method Details

#persistObject

Sends the atomic $set operation to the database.

Examples:

Persist the new values.

set.persist

Returns:

  • (Object)

    The new field value.



18
19
20
21
22
23
24
25
26
# File 'lib/mongoid/persistence/atomic/sets.rb', line 18

def persist
  prepare do
    value ? document[field] = value : @value = document[field]
    document[field].tap do
      collection.update(document.atomic_selector, operation("$set"), options)
      document.remove_change(field)
    end
  end
end