Sha256: 3c84350253f2c38bd1875e7ed4f0d88e1934b5aefea63cbc74fc3344e9fb39b8

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

# encoding: utf-8
require "mongoid/atomic/paths/embedded/one"
require "mongoid/atomic/paths/embedded/many"

module Mongoid
  module Atomic
    module Paths

      # Common functionality between the two different embedded paths.
      module Embedded

        attr_reader :delete_modifier, :document, :insert_modifier, :parent

        # Get the path to the document in the hierarchy.
        #
        # @example Get the path.
        #   many.path
        #
        # @return [ String ] The path to the document.
        #
        # @since 2.1.0
        def path
          position.sub(/\.\d+$/, "")
        end

        # Get the selector to use for the root document when performing atomic
        # updates. When sharding this will include the shard key.
        #
        # @example Get the selector.
        #   many.selector
        #
        # @return [ Hash ] The selector to identify the document with.
        #
        # @since 2.1.0
        def selector
          parent.atomic_selector.
            merge!({ "#{path}._id" => document._id }).merge!(document.shard_key_selector)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongoid-3.0.9 lib/mongoid/atomic/paths/embedded.rb
mongoid-3.0.6 lib/mongoid/atomic/paths/embedded.rb
mongoid-3.0.5 lib/mongoid/atomic/paths/embedded.rb
mongoid-3.0.4 lib/mongoid/atomic/paths/embedded.rb
mongoid-3.0.3 lib/mongoid/atomic/paths/embedded.rb
mongoid-3.0.2 lib/mongoid/atomic/paths/embedded.rb
mongoid-3.0.1 lib/mongoid/atomic/paths/embedded.rb
mongoid-3.0.0 lib/mongoid/atomic/paths/embedded.rb
mongoid-3.0.0.rc lib/mongoid/atomic/paths/embedded.rb