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
-
#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
Instance Method Details
#pull(modifications) ⇒ Object
Adds pull modifiers to the modifiers hash.
17 18 19 20 21 22 |
# File 'lib/mongoid/atomic/modifiers.rb', line 17 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.
32 33 34 35 36 37 |
# File 'lib/mongoid/atomic/modifiers.rb', line 32 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.
47 48 49 50 51 52 53 54 |
# File 'lib/mongoid/atomic/modifiers.rb', line 47 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.
64 65 66 67 68 |
# File 'lib/mongoid/atomic/modifiers.rb', line 64 def unset(modifications) modifications.each do |field| unsets.update(field => true) end end |