Module: Mongoid::Paths::InstanceMethods

Defined in:
lib/mongoid/paths.rb

Instance Method Summary collapse

Instance Method Details

#_inserterObject

Get the insertion modifier for the document. Will be nil on root documents, $set on embeds_one, $push on embeds_many.

Example:

name.inserter



16
17
18
# File 'lib/mongoid/paths.rb', line 16

def _inserter
  embedded? ? (embedded_many? ? "$push" : "$set") : nil
end

#_pathObject Also known as: _pull

Return the path to this Document in JSON notation, used for atomic updates via $set in MongoDB.

Example:

address.path # returns "addresses"



26
27
28
# File 'lib/mongoid/paths.rb', line 26

def _path
  _position.sub!(/\.\d+$/, '') || _position
end

#_positionObject

Returns the positional operator of this document for modification.

Example:

address.position



36
37
38
39
# File 'lib/mongoid/paths.rb', line 36

def _position
  locator = _index ? (new_record? ? "" : ".#{_index}") : ""
  embedded? ? "#{_parent._position}#{"." unless _parent._position.blank?}#{@association_name}#{locator}" : ""
end

#_removerObject

Get the removal modifier for the document. Will be nil on root documents, $unset on embeds_one, $set on embeds_many.

Example:

name.remover



47
48
49
# File 'lib/mongoid/paths.rb', line 47

def _remover
  embedded? ? (_index ? "$pull" : "$unset") : nil
end

#_selectorObject

Return the selector for this document to be matched exactly for use with MongoDB’s $ operator.

Example:

address.selector



57
58
59
# File 'lib/mongoid/paths.rb', line 57

def _selector
  embedded? ? _parent._selector.merge("#{_path}._id" => id) : { "_id" => id }
end