Module: Mongoid::Contexts

Defined in:
lib/mongoid/contexts/paging.rb,
lib/mongo_doc/contexts.rb,
lib/mongo_doc/contexts/ids.rb,
lib/mongoid/contexts/enumerable.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Ids, Paging Classes: Enumerable, UnknownContext

Class Method Summary collapse

Class Method Details

.context_for(criteria) ⇒ Object

Determines the context to be used for this criteria. If the class is an embedded document, then the context will be the array in the embed_many association it is in. If the class is a root, then the database itself will be the context.

Example:

Contexts.context_for(criteria)



20
21
22
23
24
25
26
27
28
# File 'lib/mongo_doc/contexts.rb', line 20

def self.context_for(criteria)
  if criteria.klass.respond_to?(:_append)
    return Mongoid::Contexts::Enumerable.new(criteria)
  elsif criteria.klass.respond_to?(:collection)
    return MongoDoc::Contexts::Mongo.new(criteria)
  else
    raise UnknownContext.new("Context not found for: #{criteria.klass}")
  end
end