Sha256: a3cb213f8a9b3872aace2b57a83cb960fc625ebac4be810b1414d3fc0820fef1

Contents?: true

Size: 844 Bytes

Versions: 188

Compression:

Stored size: 844 Bytes

Contents

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

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

        # Sends the atomic $push operation to the database.
        #
        # @example Persist the new values.
        #   push.persist
        #
        # @return [ Object ] The new array value.
        #
        # @since 2.0.0
        def persist
          prepare do
            document[field] = [] unless document[field]
            document.send(field).push(value).tap do |value|
              collection.update(document.atomic_selector, operation("$push"), options)
              document.remove_change(field)
            end
          end
        end
      end
    end
  end
end

Version data entries

188 entries across 96 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/push.rb
mongoid-2.8.1 lib/mongoid/persistence/atomic/push.rb
mongoid-2.8.0 lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/push.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/push.rb