Sha256: d1e667357d6ad64bbbdbf9f807135523e5a8306fa9ea29dcffff562f9201c939

Contents?: true

Size: 953 Bytes

Versions: 188

Compression:

Stored size: 953 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
        include 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
          prepare do
            if document[field]
              values = document.send(field)
              values.delete_if { |val| value.include?(val) }
              values.tap do
                collection.update(document.atomic_selector, operation("$pullAll"), 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.6.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/atomic/pull_all.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/atomic/pull_all.rb