Module: Mongoid::Persistable::Poppable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Mongoid::Persistable
- Defined in:
- lib/mongoid/persistable/poppable.rb
Overview
Defines behaviour for $pop operations.
Instance Method Summary collapse
-
#pop(pops) ⇒ true, false
Pop or shift items from arrays using the $pop operator.
Instance Method Details
#pop(pops) ⇒ true, false
Pop or shift items from arrays using the $pop operator.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongoid/persistable/poppable.rb', line 27 def pop(pops) prepare_atomic_operation do |ops| process_atomic_operations(pops) do |field, value| values = send(field) value > 0 ? values.pop : values.shift ops[atomic_attribute_name(field)] = value end { "$pop" => ops } end end |