Module: MongoMapper::Plugins::UpdatingModifiers::InstanceMethods
- Defined in:
- lib/mongo_mapper/plugins/updating_modifiers.rb
Instance Method Summary collapse
- #add_to_set(hash) ⇒ Object (also: #push_uniq)
- #decrement(hash) ⇒ Object
- #increment(hash) ⇒ Object
- #pull(hash) ⇒ Object
- #push(hash) ⇒ Object
- #set(hash) ⇒ Object
Instance Method Details
#add_to_set(hash) ⇒ Object Also known as: push_uniq
54 55 56 57 58 59 60 61 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 54 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 hash_to_mongo(hash) end |
#decrement(hash) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 27 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 hash_to_mongo(hash) end |
#increment(hash) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 18 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 hash_to_mongo(hash) end |
#pull(hash) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 45 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 hash_to_mongo(hash) end |
#push(hash) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 36 def push(hash) hash.each do |key, value| obj, method = get_obj_and_method(key) obj = obj.send(method) obj.push value end super hash_to_mongo(hash) end |
#set(hash) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 10 def set(hash) hash.each do |key, value| obj, method = get_obj_and_method(key) obj.send("#{method}=", value) end super hash_to_mongo(hash) end |