Class: Mongoid::AtomicUpdatePreparer Private
- Inherits:
-
Object
- Object
- Mongoid::AtomicUpdatePreparer
- Defined in:
- lib/mongoid/atomic_update_preparer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A singleton class to assist with preparing attributes for atomic updates.
Once the deprecated Hash#__consolidate__ method is removed entirely, these methods may be moved into Mongoid::Contextual::Mongo as private methods.
Class Method Summary collapse
-
.prepare(attributes, klass) ⇒ Hash
private
Convert the key/values in the attributes into a hash of atomic updates.
Class Method Details
.prepare(attributes, klass) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convert the key/values in the attributes into a hash of atomic updates. Non-operator keys are assumed to use $set operation.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mongoid/atomic_update_preparer.rb', line 21 def prepare(attributes, klass) attributes.each_pair.with_object({}) do |(key, value), atomic_updates| key = klass.database_field_name(key.to_s) if key.to_s.start_with?('$') (atomic_updates[key] ||= {}).update(prepare_operation(klass, key, value)) else (atomic_updates['$set'] ||= {})[key] = mongoize_for(key, klass, key, value) end end end |