Module: Mongoid::Persistable::Pullable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Mongoid::Persistable
- Defined in:
- lib/mongoid/persistable/pullable.rb
Overview
Defines behaviour for $pull and $pullAll operations.
Instance Method Summary collapse
-
#pull(pulls) ⇒ true, false
Pull single values from the provided arrays.
-
#pull_all(pulls) ⇒ true, false
Pull multiple values from the provided array fields.
Instance Method Details
#pull(pulls) ⇒ true, false
Note:
If duplicate values are found they will all be pulled.
Pull single values from the provided arrays.
23 24 25 26 27 28 29 30 31 |
# File 'lib/mongoid/persistable/pullable.rb', line 23 def pull(pulls) prepare_atomic_operation do |ops| process_atomic_operations(pulls) do |field, value| (send(field) || []).delete(value) ops[atomic_attribute_name(field)] = value end { "$pull" => ops } end end |
#pull_all(pulls) ⇒ true, false
Pull multiple values from the provided array fields.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mongoid/persistable/pullable.rb', line 43 def pull_all(pulls) prepare_atomic_operation do |ops| process_atomic_operations(pulls) do |field, value| existing = send(field) || [] value.each{ |val| existing.delete(val) } ops[atomic_attribute_name(field)] = value end { "$pullAll" => ops } end end |