Class: Mongoid::Atomic::Modifiers
- Defined in:
- lib/mongoid/atomic/modifiers.rb
Overview
This class contains the logic for supporting atomic operations against the database.
Instance Method Summary collapse
-
#add_to_set(modifications) ⇒ Object
Add the atomic $addToSet modifiers to the hash.
-
#pull(modifications) ⇒ Object
Adds pull modifiers to the modifiers hash.
-
#push(modifications) ⇒ Object
Adds push modifiers to the modifiers hash.
-
#set(modifications) ⇒ Object
Adds set operations to the modifiers hash.
-
#unset(modifications) ⇒ Object
Adds unset operations to the modifiers hash.
Methods included from Extensions::Hash::Scoping
Methods included from Extensions::Hash::CriteriaHelpers
#expand_complex_criteria, #extract_id
Methods included from Extensions::Hash::DeepCopy
Instance Method Details
#add_to_set(modifications) ⇒ Object
Add the atomic $addToSet modifiers to the hash.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mongoid/atomic/modifiers.rb', line 17 def add_to_set(modifications) modifications.each_pair do |field, value| if add_to_sets.has_key?(field) value.each do |val| add_to_sets[field]["$each"].push(val) end else add_to_sets[field] = { "$each" => value } end end end |
#pull(modifications) ⇒ Object
Adds pull modifiers to the modifiers hash.
37 38 39 40 41 42 |
# File 'lib/mongoid/atomic/modifiers.rb', line 37 def pull(modifications) modifications.each_pair do |field, value| add_operation(pulls, field, value) pull_fields << field.split(".", 2)[0] end end |
#push(modifications) ⇒ Object
Adds push modifiers to the modifiers hash.
52 53 54 55 56 57 |
# File 'lib/mongoid/atomic/modifiers.rb', line 52 def push(modifications) modifications.each_pair do |field, value| mods = push_conflict?(field) ? conflicting_pushes : pushes add_operation(mods, field, Array.wrap(value)) end end |
#set(modifications) ⇒ Object
Adds set operations to the modifiers hash.
67 68 69 70 71 72 73 74 |
# File 'lib/mongoid/atomic/modifiers.rb', line 67 def set(modifications) modifications.each_pair do |field, value| next if field == "_id" mods = set_conflict?(field) ? conflicting_sets : sets add_operation(mods, field, value) set_fields << field.split(".", 2)[0] end end |
#unset(modifications) ⇒ Object
Adds unset operations to the modifiers hash.
84 85 86 87 88 |
# File 'lib/mongoid/atomic/modifiers.rb', line 84 def unset(modifications) modifications.each do |field| unsets.update(field => true) end end |