Sha256: 3e54ac472e5aa349c7a1568a96c69c91bed0a19de3b169e9303037e3293d677e

Contents?: true

Size: 1.58 KB

Versions: 15

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Paths #:nodoc:
    extend ActiveSupport::Concern
    included do
      cattr_accessor :__path
      attr_accessor :_index
    end

    # Get the insertion modifier for the document. Will be nil on root
    # documents, $set on embeds_one, $push on embeds_many.
    #
    # Example:
    #
    # <tt>name.inserter</tt>
    def _inserter
      embedded? ? (embedded_many? ? "$push" : "$set") : nil
    end

    # Return the path to this +Document+ in JSON notation, used for atomic
    # updates via $set in MongoDB.
    #
    # Example:
    #
    # <tt>address.path # returns "addresses"</tt>
    def _path
      _position.sub!(/\.\d+$/, '') || _position
    end
    alias :_pull :_path

    # Returns the positional operator of this document for modification.
    #
    # Example:
    #
    # <tt>address.position</tt>
    def _position
      locator = _index ? (new_record? ? "" : ".#{_index}") : ""
      embedded? ? "#{_parent._position}#{"." unless _parent._position.blank?}#{@association_name}#{locator}" : ""
    end

    # Get the removal modifier for the document. Will be nil on root
    # documents, $unset on embeds_one, $set on embeds_many.
    #
    # Example:
    #
    # <tt>name.remover</tt>
    def _remover
      embedded? ? (_index ? "$pull" : "$unset") : nil
    end

    # Return the selector for this document to be matched exactly for use
    # with MongoDB's $ operator.
    #
    # Example:
    #
    # <tt>address.selector</tt>
    def _selector
      embedded? ? _parent._selector.merge("#{_path}._id" => id) : { "_id" => id }
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
mongoid-2.0.0.beta.20 lib/mongoid/paths.rb
mongoid-2.0.0.beta.19 lib/mongoid/paths.rb
mongoid-2.0.0.beta.18 lib/mongoid/paths.rb
mongoid-2.0.0.beta.17 lib/mongoid/paths.rb
mongoid-2.0.0.beta.16 lib/mongoid/paths.rb
mongoid-2.0.0.beta.15 lib/mongoid/paths.rb
mongoid-2.0.0.beta.14 lib/mongoid/paths.rb
mongoid-2.0.0.beta.13 lib/mongoid/paths.rb
mongoid-2.0.0.beta.11 lib/mongoid/paths.rb
mongoid-2.0.0.beta.10 lib/mongoid/paths.rb
mongoid-2.0.0.beta.7 lib/mongoid/paths.rb
mongoid-2.0.0.beta.8 lib/mongoid/paths.rb
mongoid-2.0.0.beta.9 lib/mongoid/paths.rb
mongoid-2.0.0.beta.12 lib/mongoid/paths.rb
mongoid-locomotive-2.0.0.beta9 lib/mongoid/paths.rb