Sha256: df9faebd312673d01a21cc402dab2b84b13cee1ed4c049614ca1b02eb1045ea3

Contents?: true

Size: 1.34 KB

Versions: 26

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Atomic
    module Paths
      module Embedded

        # This class encapsulates behavior for locating and updating
        # documents that are defined as an embedded 1-n.
        class Many
          include Embedded

          # Create the new path utility.
          #
          # @example Create the path util.
          #   Many.new(document)
          #
          # @param [ Document ] document The document to generate the paths for.
          #
          # @since 2.1.0
          def initialize(document)
            @document, @parent = document, document._parent
            @insert_modifier, @delete_modifier ="$push", "$pull"
          end

          # Get the position of the document in the hierarchy. This will
          # include indexes of 1-n embedded associations that may sit above the
          # embedded many.
          #
          # @example Get the position.
          #   many.position
          #
          # @return [ String ] The position of the document.
          #
          # @since 2.1.0
          def position
            pos = parent.atomic_position
            locator = document.new_record? ? "" : ".#{document._index}"
            "#{pos}#{"." unless pos.blank?}#{document._association.store_as}#{locator}"
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
mongoid-7.3.4 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.1.11 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.2.6 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.3.3 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.3.2 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.2.5 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.1.10 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.1.9 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.2.4 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.3.1 lib/mongoid/atomic/paths/embedded/many.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.3.0 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.2.3 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.1.8 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.2.2 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.2.1 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.1.7 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.2.0 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.1.6 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-7.1.5 lib/mongoid/atomic/paths/embedded/many.rb