Sha256: aebdbac0c094fc949a223e246496f1a32a2b79149dcfb616c55e70017a0848be

Contents?: true

Size: 744 Bytes

Versions: 32

Compression:

Stored size: 744 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Persistence
    module Atomic

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

        # Sends the atomic $pop operation to the database.
        #
        # @example Persist the new values.
        #   pop.persist
        #
        # @return [ Object ] The new array value.
        #
        # @since 2.1.0
        def persist
          prepare do
            if document[field]
              values = document.send(field)
              value > 0 ? values.pop : values.shift
              execute("$pop")
              values
            end
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
mongoid-3.1.7 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.1.6 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.1.5 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.1.4 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.1.3 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.1.2 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.23 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.1.1 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.1.0 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.22 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.21 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.20 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.19 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.18 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.17 lib/mongoid/persistence/atomic/pop.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.16/lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.16 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.15 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.14 lib/mongoid/persistence/atomic/pop.rb
mongoid-3.0.13 lib/mongoid/persistence/atomic/pop.rb