Sha256: ed87f304ae1735d75b2dc500998679a0b844fa41270b60d492eadae1a6b9374f

Contents?: true

Size: 1.31 KB

Versions: 53

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8
module Mongoid
  module Atomic
    module Paths
      module Embedded

        # This class encapsulates behaviour 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 relations 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.__metadata.store_as}#{locator}"
          end
        end
      end
    end
  end
end

Version data entries

53 entries across 48 versions & 3 rubygems

Version Path
mongoid-6.4.8 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.4.7 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.4.5 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-5.4.1 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.4.4 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.4.2 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.4.1 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-5.4.0 lib/mongoid/atomic/paths/embedded/many.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.4.0 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.3.0 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.2.1 lib/mongoid/atomic/paths/embedded/many.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/atomic/paths/embedded/many.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.2.0/lib/mongoid/atomic/paths/embedded/many.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.2.0 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.1.1 lib/mongoid/atomic/paths/embedded/many.rb
mongoid-5.2.1 lib/mongoid/atomic/paths/embedded/many.rb
tdiary-5.0.4 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/atomic/paths/embedded/many.rb
mongoid-6.1.0 lib/mongoid/atomic/paths/embedded/many.rb