Sha256: bb6ad164ab5dd2060cf505e15f19107a170e14032532494caeebaddec9f278bb

Contents?: true

Size: 1.72 KB

Versions: 193

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Relations #:nodoc:
    module Embedded #:nodoc:
      module Atomic #:nodoc:

        class Pull < Operation

          # Get the merged operations for the single atomic set.
          #
          # @example Get the operations
          #   set.operations
          #
          # @return [ Hash ] The pull operations.
          #
          # @since 2.0.0
          def operations
            { "$pull" =>
              { path =>
                { "_id" =>
                  { "$in" => documents.map { |doc| doc["_id"] } }
                }
              }
            }
          end

          private

          # Parses the incoming operations to get the documents to set.
          #
          # @example Parse the operations.
          #   set.parse(
          #     { "$pull" => { "addresses" => { "_id" => "street" } } }
          #   )
          #
          # @param [ Hash ] operations The ops to parse.
          #
          # @since 2.0.0
          def parse(operations)
            modifier = operations.keys.first
            extract(modifier, operations[modifier])
          end

          # Extract a document from the operation.
          #
          # @example Extract the document.
          #   set.extract({ "$pull" => [{ "_id" => "street" }] })
          #
          # @param [ Hash ] operation The op to extract from.
          #
          # @since 2.0.0
          def extract(modifier, operations)
            @path = operations.keys.first
            case modifier
            when "$pull"
              documents.push(operations[path])
            when "$pullAll"
              documents.concat(operations[path])
            end
          end
        end
      end
    end
  end
end

Version data entries

193 entries across 101 versions & 5 rubygems

Version Path
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/embedded/atomic/pull.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/embedded/atomic/pull.rb