module Mongoid::Atomic::Paths::Embedded

Common functionality between the two different embedded paths.

Attributes

delete_modifier[R]
document[R]
insert_modifier[R]
parent[R]

Public Instance Methods

path() click to toggle source

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

# File lib/mongoid/atomic/paths/embedded.rb, line 21
def path
  @path ||= position.sub(/\.\d+$/, "")
end
selector() click to toggle source

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

# File lib/mongoid/atomic/paths/embedded.rb, line 34
def selector
  @selector ||= generate_selector
end

Private Instance Methods

generate_selector() click to toggle source
# File lib/mongoid/atomic/paths/embedded.rb, line 40
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
only_root_selector?() click to toggle source
# File lib/mongoid/atomic/paths/embedded.rb, line 51
def only_root_selector?
  document.persisted? && document._id_changed?
end