Module: MongoMapper::Plugins::UpdatingModifiers::InstanceMethods

Defined in:
lib/mongo_mapper/plugins/updating_modifiers.rb

Instance Method Summary collapse

Instance Method Details

#add_to_set(hash) ⇒ Object Also known as: push_uniq



52
53
54
55
56
57
58
59
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 52

def add_to_set(hash)
  hash.each do |key, value|
    obj, method = get_obj_and_method(key)
    obj = obj.send(method)
    obj.push(value) unless obj.include?(value)
  end
  super
end

#decrement(hash) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 25

def decrement(hash)
  hash.each do |key, value|
    obj, method = get_obj_and_method(key)
    val = obj.send(method)
    obj.send("#{method}=", val - value)
  end
  super
end

#increment(hash) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 16

def increment(hash)
  hash.each do |key, value|
    obj, method = get_obj_and_method(key)
    val = obj.send(method)
    obj.send("#{method}=", val + value)
  end
  super
end

#pull(hash) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 43

def pull(hash)
  hash.each do |key, value|
    obj, method = get_obj_and_method(key)
    obj = obj.send(method)
    obj.delete_if { |e| e == value }
  end
  super
end

#push(hash) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 34

def push(hash)
  hash.each do |key, value|
    obj, method = get_obj_and_method(key)
    obj = obj.send(method)
    obj.push value
  end
  super
end

#set(hash) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 8

def set(hash)
  hash.each do |key, value|
    obj, method = get_obj_and_method(key)
    obj.send("#{method}=", value)
  end
  super
end