Class: Mongoid::Persistence::Atomic::Pop

Inherits:
Object
  • Object
show all
Includes:
Operation
Defined in:
lib/mongoid/persistence/atomic/pop.rb

Overview

This class provides the ability to perform an explicit $pop modification on a specific field.

Instance Attribute Summary

Attributes included from Operation

#document, #field, #options, #value

Instance Method Summary collapse

Methods included from Operation

#collection, #initialize, #operation, #path, #prepare

Instance Method Details

#persistObject

Sends the atomic $pop operation to the database.

Examples:

Persist the new values.

pop.persist

Returns:

  • (Object)

    The new array value.

Since:

  • 2.1.0



19
20
21
22
23
24
25
26
27
28
# File 'lib/mongoid/persistence/atomic/pop.rb', line 19

def persist
  prepare do
    if document[field]
      values = document.send(field)
      value > 0 ? values.pop : values.shift
      execute("$pop")
      values
    end
  end
end