Class: Mongoid::Atomic::Modifiers

Inherits:
Hash
  • Object
show all
Defined in:
lib/patches/push_each.rb

Instance Method Summary collapse

Instance Method Details

#add_each_operation(mods, field, value) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/patches/push_each.rb', line 41

def add_each_operation(mods, field, value)
  value = Array.wrap(value)
  if mods.has_key?(field)
    value.each do |val|
      mods[field]["$each"].push(val)
    end
  else
    mods[field] = { "$each" => value }
  end
end

#conflicting_pushesObject



52
53
54
# File 'lib/patches/push_each.rb', line 52

def conflicting_pushes
  conflicts["$push"] ||= {}
end

#push(modifications) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/patches/push_each.rb', line 33

def push(modifications)
  modifications.each_pair do |field, value|
    push_fields[field] = field
    mods = push_conflict?(field) ? conflicting_pushes : pushes
    add_each_operation(mods, field, value)
  end
end

#pushesObject



56
57
58
# File 'lib/patches/push_each.rb', line 56

def pushes
  self["$push"] ||= {}
end