Module: MongoMapper::Plugins::Modifiers::ClassMethods
- Defined in:
- lib/mongo_mapper/plugins/modifiers.rb
Instance Method Summary collapse
- #decrement(*args) ⇒ Object
- #increment(*args) ⇒ Object
- #pop(*args) ⇒ Object
- #pull(*args) ⇒ Object
- #pull_all(*args) ⇒ Object
- #push(*args) ⇒ Object
- #push_all(*args) ⇒ Object
- #push_uniq(*args) ⇒ Object
- #set(*args) ⇒ Object
Instance Method Details
#decrement(*args) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 9 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
5 6 7 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 5 def increment(*args) modifier_update('$inc', args) end |
#pop(*args) ⇒ Object
42 43 44 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 42 def pop(*args) modifier_update('$pop', args) end |
#pull(*args) ⇒ Object
34 35 36 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 34 def pull(*args) modifier_update('$pull', args) end |
#pull_all(*args) ⇒ Object
38 39 40 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 38 def pull_all(*args) modifier_update('$pullAll', args) end |
#push(*args) ⇒ Object
20 21 22 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 20 def push(*args) modifier_update('$push', args) end |
#push_all(*args) ⇒ Object
24 25 26 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 24 def push_all(*args) modifier_update('$pushAll', args) end |
#push_uniq(*args) ⇒ Object
28 29 30 31 32 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 28 def push_uniq(*args) criteria, keys = criteria_and_keys_from_args(args) keys.each { |key, value | criteria[key] = {'$ne' => value} } collection.update(criteria, {'$push' => keys}, :multi => true) end |
#set(*args) ⇒ Object
16 17 18 |
# File 'lib/mongo_mapper/plugins/modifiers.rb', line 16 def set(*args) modifier_update('$set', args) end |