Sha256: 34d237b925fd071fb521971e1a29758505af08505f0d6142a818b06db45deb4d
Contents?: true
Size: 1.71 KB
Versions: 8
Compression:
Stored size: 1.71 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Paths #:nodoc: extend ActiveSupport::Concern included do attr_accessor :__path attr_accessor :_index end module InstanceMethods # 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 end
Version data entries
8 entries across 8 versions & 4 rubygems