forked from mongodb/mongoid
/
embedded.rb
42 lines (37 loc) · 1.1 KB
/
embedded.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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