Sha256: 1eb8eeec5a3dc5f5045ccd8d9df47ad0352306391486af4f01c87263bb56975d

Contents?: true

Size: 935 Bytes

Versions: 5

Compression:

Stored size: 935 Bytes

Contents

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

      # This class provides the ability to perform an explicit $pullAll
      # modification on a specific field.
      class PullAll < Operation

        # Sends the atomic $pullAll operation to the database.
        #
        # @example Persist the new values.
        #   pull_all.persist
        #
        # @return [ Object ] The new array value.
        #
        # @since 2.0.0
        def persist
          if document[field]
            values = document.send(field)
            values.delete_if { |val| value.include?(val) }
            values.tap do
              document.collection.update(document._selector, operation("$pullAll"), options)
              document.changes.delete(field.to_s) if document.persisted?
            end
          else
            return nil
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mongoid-braxton-2.0.2 lib/mongoid/persistence/atomic/pull_all.rb
mongoid-2.0.2 lib/mongoid/persistence/atomic/pull_all.rb
mongoid-2.0.1 lib/mongoid/persistence/atomic/pull_all.rb
mongoid-2.0.0 lib/mongoid/persistence/atomic/pull_all.rb
mongoid-2.0.0.rc.8 lib/mongoid/persistence/atomic/pull_all.rb