Class: Mongoid::Atomic::Paths::Embedded::One

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Atomic::Paths::Embedded
Defined in:
build/mongoid-7.0/lib/mongoid/atomic/paths/embedded/one.rb

Overview

This class encapsulates behaviour for locating and updating documents that are defined as an embedded 1-1.

Instance Attribute Summary

Attributes included from Mongoid::Atomic::Paths::Embedded

#delete_modifier, #document, #insert_modifier, #parent

Instance Method Summary collapse

Methods included from Mongoid::Atomic::Paths::Embedded

#path

Constructor Details

#initialize(document) ⇒ One

Create the new path utility.

Examples:

Create the path util.

One.new(document)

Parameters:

  • document (Document)

    The document to generate the paths for.

Since:

  • 2.1.0



20
21
22
23
# File 'build/mongoid-7.0/lib/mongoid/atomic/paths/embedded/one.rb', line 20

def initialize(document)
  @document, @parent = document, document._parent
  @insert_modifier, @delete_modifier ="$set", "$unset"
end

Instance Method Details

#positionString

Get the position of the document in the hierarchy. This will include indexes of 1-n embedded relations that may sit above the embedded one.

Examples:

Get the position.

one.position

Returns:

  • (String)

    The position of the document.

Since:

  • 2.1.0



35
36
37
38
# File 'build/mongoid-7.0/lib/mongoid/atomic/paths/embedded/one.rb', line 35

def position
  pos = parent.atomic_position
  "#{pos}#{"." unless pos.blank?}#{document._association.store_as}"
end