Module: MongoMapper::Plugins::UpdatingModifiers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongo_mapper/plugins/updating_modifiers.rb
Class Method Summary collapse
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
Class Method Details
.configure(mod) ⇒ Object
6 7 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 6 def self.configure(mod) end |
Instance Method Details
#add_to_set(hash) ⇒ Object Also known as: push_uniq
53 54 55 56 57 58 59 60 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 53 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
26 27 28 29 30 31 32 33 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 26 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
17 18 19 20 21 22 23 24 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 17 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
44 45 46 47 48 49 50 51 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 44 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
35 36 37 38 39 40 41 42 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 35 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
9 10 11 12 13 14 15 |
# File 'lib/mongo_mapper/plugins/updating_modifiers.rb', line 9 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 |