Sha256: 0990f1780d3107c65b95295abc65d40f7d21341119dad8e395fcce0630cccd16

Contents?: true

Size: 936 Bytes

Versions: 17

Compression:

Stored size: 936 Bytes

Contents

# encoding: utf-8
require "mongoid/contexts/paging"
require "mongo_doc/contexts/ids"
require "mongoid/contexts/enumerable"
require "mongo_doc/contexts/mongo"

module Mongoid
  module Contexts

    class UnknownContext < RuntimeError; end

    # 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:
    #
    # <tt>Contexts.context_for(criteria)</tt>
    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

  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
mongo_doc-0.6.11 lib/mongo_doc/contexts.rb
mongo_doc-0.6.10 lib/mongo_doc/contexts.rb
mongo_doc-0.6.9 lib/mongo_doc/contexts.rb
mongo_doc-0.6.8 lib/mongo_doc/contexts.rb
mongo_doc-0.6.7 lib/mongo_doc/contexts.rb
mongo_doc-0.6.6 lib/mongo_doc/contexts.rb
mongo_doc-0.6.5 lib/mongo_doc/contexts.rb
mongo_doc-0.6.4 lib/mongo_doc/contexts.rb
mongo_doc_rails2-0.6.2 lib/mongo_doc/contexts.rb
mongo_doc-0.6.3 lib/mongo_doc/contexts.rb
mongo_doc-0.6.2 lib/mongo_doc/contexts.rb
mongo_doc-0.6.1 lib/mongo_doc/contexts.rb
mongo_doc-0.6.0 lib/mongo_doc/contexts.rb
mongo_doc_rails2-0.6.1 lib/mongo_doc/contexts.rb
mongo_doc-0.5.5 lib/mongo_doc/contexts.rb
mongo_doc-0.4.2 lib/mongo_doc/contexts.rb
mongo_doc-0.4.1 lib/mongo_doc/contexts.rb