Sha256: 655b3adf383814003fbd2d994305d77130b8e30a5d6ec13e6f116c63f9419d2e

Contents?: true

Size: 1022 Bytes

Versions: 14

Compression:

Stored size: 1022 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Persistable

    # Defines behaviour for $pop operations.
    #
    # @since 4.0.0
    module Poppable
      extend ActiveSupport::Concern

      # Pop or shift items from arrays using the $pop operator.
      #
      # @example Pop items from an array.
      #   document.pop(aliases: 1)
      #
      # @example Shift items in the array.
      #   document.pop(aliases: -1)
      #
      # @example Multiple pops in one call.
      #   document.pop(names: 1, aliases: 1)
      #
      # @param [ Hash ] pops The field/value pop operations.
      #
      # @return [ true, false ] If the operation succeeded.
      #
      # @since 4.0.0
      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
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/lib/mongoid/persistable/poppable.rb
mongoid-4.0.2 lib/mongoid/persistable/poppable.rb
mongoid-4.0.1 lib/mongoid/persistable/poppable.rb
mongoid-4.0.0 lib/mongoid/persistable/poppable.rb
mongoid-4.0.0.rc2 lib/mongoid/persistable/poppable.rb
mongoid-4.0.0.rc1 lib/mongoid/persistable/poppable.rb
mongoid-4.0.0.beta2 lib/mongoid/persistable/poppable.rb
mongoid-4.0.0.beta1 lib/mongoid/persistable/poppable.rb
mongoid-4.0.0.alpha2 lib/mongoid/persistable/poppable.rb
mongoid-4.0.0.alpha1 lib/mongoid/persistable/poppable.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/persistable/poppable.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/persistable/poppable.rb
mongoid_heroku_stable-4.0.0 lib/mongoid/persistable/poppable.rb
mongoid_rails4-4.0.0 lib/mongoid/persistable/poppable.rb