Sha256: 0a9a41d9f522928b5bc546d7c0d56f361b3cb17d3f8b1393dc4c730c359a73f8

Contents?: true

Size: 1.66 KB

Versions: 193

Compression:

Stored size: 1.66 KB

Contents

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

        class Set < Operation

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

          private

          # Parses the incoming operations to get the documents to set.
          #
          # @example Parse the operations.
          #   set.parse(
          #     { "addresses" => { "$pushAll" => [{ "_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({ "$pushAll" => [{ "_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 "$push"
              documents.push(operations[path])
            when "$pushAll"
              documents.push(operations[path].first)
            when "$set"
              @documents = operations[path]
            end
          end
        end
      end
    end
  end
end

Version data entries

193 entries across 101 versions & 5 rubygems

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