Module: MongoMapper::Plugins::Modifiers::ClassMethods
- Defined in:
- lib/mongo_mapper/plugins/modifiers.rb
Instance Method Summary collapse
- #add_to_set(*args) ⇒ Object (also: #push_uniq)
- #decrement(*args) ⇒ Object
- #increment(*args) ⇒ Object
- #pop(*args) ⇒ Object
- #pull(*args) ⇒ Object
- #pull_all(*args) ⇒ Object
- #push(*args) ⇒ Object
- #push_all(*args) ⇒ Object
- #set(*args) ⇒ Object
- #unset(*args) ⇒ Object
Instance Method Details
#add_to_set(*args) ⇒ Object Also known as: push_uniq
46 47 48 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 46 def add_to_set(*args) modifier_update('$addToSet', args) end |
#decrement(*args) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 10 def decrement(*args) criteria, keys = criteria_and_keys_from_args(args) values, to_decrement = keys.values, {} keys.keys.each_with_index { |k, i| to_decrement[k] = -values[i].abs } collection.update(criteria, {'$inc' => to_decrement}, :multi => true) end |
#increment(*args) ⇒ Object
6 7 8 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 6 def increment(*args) modifier_update('$inc', args) end |
#pop(*args) ⇒ Object
59 60 61 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 59 def pop(*args) modifier_update('$pop', args) end |
#pull(*args) ⇒ Object
51 52 53 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 51 def pull(*args) modifier_update('$pull', args) end |
#pull_all(*args) ⇒ Object
55 56 57 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 55 def pull_all(*args) modifier_update('$pullAll', args) end |
#push(*args) ⇒ Object
38 39 40 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 38 def push(*args) modifier_update('$push', args) end |
#push_all(*args) ⇒ Object
42 43 44 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 42 def push_all(*args) modifier_update('$pushAll', args) end |
#set(*args) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 17 def set(*args) criteria, updates = criteria_and_keys_from_args(args) updates.each do |key, value| updates[key] = keys[key].set(value) if key?(key) end collection.update(criteria, {'$set' => updates}, :multi => true) end |
#unset(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 25 def unset(*args) if args[0].is_a?(Hash) criteria, keys = args.shift, args else keys, ids = args.partition { |arg| arg.is_a?(Symbol) } criteria = {:id => ids} end criteria = criteria_hash(criteria).to_hash modifiers = keys.inject({}) { |hash, key| hash[key] = 1; hash } collection.update(criteria, {'$unset' => modifiers}, :multi => true) end |