Sha256: 030eec7d09e4f70a65285e4fc185c6743a1f850a0d163de4a082a83f8e1b66ca
Contents?: true
Size: 1.43 KB
Versions: 8
Compression:
Stored size: 1.43 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 @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 @selector ||= generate_selector end private def generate_selector if only_root_selector? parent.atomic_selector else parent. atomic_selector. merge("#{path}._id" => document._id). merge(document.shard_key_selector) end end def only_root_selector? document.persisted? && document._id_changed? end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems