Sha256: 09755e08da4a224382a3c98fe013ef9bec0d859f1adeeb5ea74b6d9f9698c22d

Contents?: true

Size: 977 Bytes

Versions: 22

Compression:

Stored size: 977 Bytes

Contents

# encoding: utf-8
require "mongoid/contexts/paging"
require "mongoid/contexts/id_conversion"
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

22 entries across 22 versions & 1 rubygems

Version Path
mongo_doc-0.6.34 lib/mongo_doc/contexts.rb
mongo_doc-0.6.33 lib/mongo_doc/contexts.rb
mongo_doc-0.6.32 lib/mongo_doc/contexts.rb
mongo_doc-0.6.31 lib/mongo_doc/contexts.rb
mongo_doc-0.6.30 lib/mongo_doc/contexts.rb
mongo_doc-0.6.29 lib/mongo_doc/contexts.rb
mongo_doc-0.6.28 lib/mongo_doc/contexts.rb
mongo_doc-0.6.27 lib/mongo_doc/contexts.rb
mongo_doc-0.6.26 lib/mongo_doc/contexts.rb
mongo_doc-0.6.25 lib/mongo_doc/contexts.rb
mongo_doc-0.6.23 lib/mongo_doc/contexts.rb
mongo_doc-0.6.22 lib/mongo_doc/contexts.rb
mongo_doc-0.6.21 lib/mongo_doc/contexts.rb
mongo_doc-0.6.20 lib/mongo_doc/contexts.rb
mongo_doc-0.6.19 lib/mongo_doc/contexts.rb
mongo_doc-0.6.18 lib/mongo_doc/contexts.rb
mongo_doc-0.6.17 lib/mongo_doc/contexts.rb
mongo_doc-0.6.16 lib/mongo_doc/contexts.rb
mongo_doc-0.6.15 lib/mongo_doc/contexts.rb
mongo_doc-0.6.14 lib/mongo_doc/contexts.rb