Module: Mongoid::Paths::InstanceMethods
- Defined in:
- lib/mongoid/paths.rb
Instance Method Summary collapse
-
#_inserter ⇒ Object
Get the insertion modifier for the document.
-
#_path ⇒ Object
(also: #_pull)
Return the path to this
Document
in JSON notation, used for atomic updates via $set in MongoDB. -
#_position ⇒ Object
Returns the positional operator of this document for modification.
-
#_remover ⇒ Object
Get the removal modifier for the document.
-
#_selector ⇒ Object
Return the selector for this document to be matched exactly for use with MongoDB’s $ operator.
Instance Method Details
#_inserter ⇒ Object
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 ? ( ? "$push" : "$set") : nil end |
#_path ⇒ Object 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 |
#_position ⇒ Object
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}") : "" ? "#{_parent._position}#{"." unless _parent._position.blank?}#{@association_name}#{locator}" : "" end |
#_remover ⇒ Object
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 ? (_index ? "$pull" : "$unset") : nil end |
#_selector ⇒ Object
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 ? _parent._selector.merge("#{_path}._id" => id) : { "_id" => id } end |