Sha256: 8705efb4e054d3bc11d90a0521c1feb165ffd6dd0ef74b95ea621244ed3b1bc5

Contents?: true

Size: 911 Bytes

Versions: 188

Compression:

Stored size: 911 Bytes

Contents

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

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

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

Version data entries

188 entries across 96 versions & 4 rubygems

Version Path
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.15 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.15 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.15 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.14 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.14 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.14 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.13 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.13 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.13 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull.rb
mongoid-2.5.0 lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.12 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.12 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.12 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.11 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.11 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.11 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.10 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.10 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull.rb
classiccms-0.5.10 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull.rb