module Mongoid::Contextual
Parent mixin module which adds aggregation (sum, avg, etc.) and atomic (set, unset, push, etc.) behavior to Mongoid::Criteria
.
Public Instance Methods
Get the context in which criteria queries should execute. This is either in memory (for embedded documents) or mongo (for root level documents.)
@example Get the context.
criteria.context
@return [ Memory
| Mongo
] The context.
# File lib/mongoid/contextual.rb, line 38 def context @context ||= create_context end
Instructs the context to schedule an asynchronous loading of documents specified by the criteria.
Note that depending on the context and on the Mongoid
configuration, documents can be loaded synchronously on the caller’s thread.
@return [ Criteria
] Returns self.
# File lib/mongoid/contextual.rb, line 49 def load_async context.load_async if context.respond_to?(:load_async) self end
Private Instance Methods
Create the context for the queries to execute. Will be memory for embedded documents and mongo for root documents.
@api private
@example Create the context.
contextual.create_context
@return [ Mongo
| Memory
] The context.
# File lib/mongoid/contextual.rb, line 65 def create_context return None.new(self) if empty_and_chainable? embedded ? Memory.new(self) : Mongo.new(self) end