Module: Mongoid::Persistable::Settable

Extended by:
ActiveSupport::Concern
Included in:
Mongoid::Persistable
Defined in:
lib/mongoid/persistable/settable.rb

Overview

Defines behaviour for $set operations.

Since:

  • 4.0.0

Instance Method Summary collapse

Instance Method Details

#set(setters) ⇒ true

Perform a $set operation on the provided field/value pairs and set the values in the document in memory.

Examples:

Set the values.

document.set(title: "sir", dob: Date.new(1970, 1, 1))

Parameters:

  • setters (Hash)

    The field/value pairs to set.

Returns:

  • (true)

    If the operation succeeded.

Since:

  • 4.0.0



22
23
24
25
26
27
28
29
30
# File 'lib/mongoid/persistable/settable.rb', line 22

def set(setters)
  prepare_atomic_operation do |ops|
    process_atomic_operations(setters) do |field, value|
      send("#{field}=", value)
      ops[atomic_attribute_name(field)] = attributes[field]
    end
    { "$set" => ops }
  end
end