Class/Module Index [+]

Quicksearch

Mongoid::Atomic

This module contains the logic for supporting atomic operations against the database.

Public Instance Methods

_updates() click to toggle source
Alias for: atomic_updates
add_atomic_pull(document) click to toggle source

Add the document as an atomic pull.

@example Add the atomic pull.

person.add_atomic_pull(address)

@param [ Document ] The embedded document to pull.

@since 2.2.0

# File lib/mongoid/atomic.rb, line 122
def add_atomic_pull(document)
  document.flagged_for_destroy = true
  (delayed_atomic_pulls[document.metadata.name.to_s] ||= []).push(document)
end
atomic_delete_modifier() click to toggle source

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

@example Get the removal operator.

name.atomic_delete_modifier

@return [ String ] The pull or unset operation.

# File lib/mongoid/atomic.rb, line 58
def atomic_delete_modifier
  atomic_paths.delete_modifier
end
atomic_insert_modifier() click to toggle source

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

@example Get the insert operation.

name.atomic_insert_modifier

@return [ String ] The pull or set operator.

# File lib/mongoid/atomic.rb, line 69
def atomic_insert_modifier
  atomic_paths.insert_modifier
end
atomic_path() click to toggle source

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

@example Get the path to this document.

address.atomic_path

@return [ String ] The path to the document in the database.

# File lib/mongoid/atomic.rb, line 80
def atomic_path
  atomic_paths.path
end
atomic_position() click to toggle source

Returns the positional operator of this document for modification.

@example Get the positional operator.

address.atomic_position

@return [ String ] The positional operator with indexes.

# File lib/mongoid/atomic.rb, line 90
def atomic_position
  atomic_paths.position
end
atomic_pulls() click to toggle source

Get all the attributes that need to be pulled.

@example Get the pulls.

person.atomic_pulls

@return [ Array<Hash> ] The $pullAll operations.

@since 2.2.0

# File lib/mongoid/atomic.rb, line 102
def atomic_pulls
  delayed_atomic_pulls.inject({}) do |pulls, (name, docs)|
    pulls.tap do |pull|
      docs.each do |doc|
        (pull[doc.atomic_path] ||= []).push(doc.as_document)
        doc.destroyed = true
        doc.flagged_for_destroy = false
      end
    end
  end
end
atomic_pushes() click to toggle source

Get all the push attributes that need to occur.

@example Get the pushes.

person.atomic_pushes

@return [ Hash ] The $pushAll operations.

@since 2.1.0

# File lib/mongoid/atomic.rb, line 135
def atomic_pushes
  pushable? ? { atomic_path => as_document } : {}
end
atomic_selector() click to toggle source

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

@example Get the selector.

address.atomic_selector

@return [ String ] The exact selector for this document.

# File lib/mongoid/atomic.rb, line 146
def atomic_selector
  atomic_paths.selector
end
atomic_sets() click to toggle source

Get all the attributes that need to be set.

@example Get the sets.

person.atomic_sets

@return [ Hash ] The $set operations.

@since 2.1.0

# File lib/mongoid/atomic.rb, line 158
def atomic_sets
  updateable? ? setters : settable? ? { atomic_path => as_document } : {}
end
atomic_unsets() click to toggle source

Get all the attributes that need to be unset.

@example Get the unsets.

person.atomic_unsets

@return [ Array<Hash> ] The $unset operations.

@since 2.2.0

# File lib/mongoid/atomic.rb, line 170
def atomic_unsets
  @atomic_unsets ||= []
end
atomic_updates() click to toggle source

Get all the atomic updates that need to happen for the current Document. This includes all changes that need to happen in the entire hierarchy that exists below where the save call was made.

@note MongoDB does not allow “conflicting modifications” to be

performed in a single operation. Conflicting modifications are
detected by the 'haveConflictingMod' function in MongoDB.
Examination of the code suggests that two modifications (a $set
and a $pushAll, for example) conflict if:
  (1) the key paths being modified are equal.
  (2) one key path is a prefix of the other.
So a $set of 'addresses.0.street' will conflict with a $pushAll
to 'addresses', and we will need to split our update into two
pieces. We do not, however, attempt to match MongoDB's logic
exactly. Instead, we assume that two updates conflict if the
first component of the two key paths matches.

@example Get the updates that need to occur.

person.atomic_updates(children)

@return [ Hash ] The updates and their modifiers.

@since 2.1.0

# File lib/mongoid/atomic.rb, line 41
def atomic_updates
  Modifiers.new.tap do |mods|
    generate_atomic_updates(mods, self)
    _children.each do |child|
      generate_atomic_updates(mods, child)
    end
  end
end
Also aliased as: _updates
delayed_atomic_pulls() click to toggle source

Get a hash of atomic pulls that are pending.

@example Get the atomic pulls.

document.delayed_atomic_pulls

@return [ Hash ] name/document pairs.

@since 2.3.2

# File lib/mongoid/atomic.rb, line 194
def delayed_atomic_pulls
  @delayed_atomic_pulls ||= {}
end
delayed_atomic_sets() click to toggle source

Get all the atomic sets that have had their saves delayed.

@example Get the delayed atomic sets.

person.delayed_atomic_sets

@return [ Hash ] The delayed $sets.

@since 2.3.0

# File lib/mongoid/atomic.rb, line 182
def delayed_atomic_sets
  @delayed_atomic_sets ||= {}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.