Sha256: f8617c6f096e9c5230d61a8be08824f9ada92c0996fc5ffc6e11dbb6bc229601

Contents?: true

Size: 1.28 KB

Versions: 9

Compression:

Stored size: 1.28 KB

Contents

module Mongoid #:nodoc
  module Errors #:nodoc

    # Raised when querying the database for a document by a specific id which
    # does not exist.
    class DocumentNotFound < RuntimeError
      def initialize(klass, identifier)
        @klass, @identifier = klass, identifier
      end
      def message
        "Document not found for class #{@klass} and id #{@identifier}"
      end
    end

    # Raised when invalid options are passed into a constructor.
    class InvalidOptions < RuntimeError; end

    # Raised when the database connection has not been set up.
    class InvalidDatabase < RuntimeError; end

    # Raised when a persisence method ending in ! fails validation.
    class Validations < RuntimeError
      def initialize(errors)
        @errors = errors
      end
      def message
        "Validation failed: #{@errors.full_messages}"
      end
    end

    # This error is raised when trying to access a Mongo::Collection from an
    # embedded document.
    class InvalidCollection < RuntimeError
      def initialize(klass)
        @klass = klass
      end
      def message
        "Access to the collection for #{@klass.name} is not allowed " +
          "since it is an embedded document, please access a collection from " +
          "the root document"
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongoid-0.10.5 lib/mongoid/errors.rb
mongoid-0.10.4 lib/mongoid/errors.rb
mongoid-0.10.3 lib/mongoid/errors.rb
mongoid-0.10.2 lib/mongoid/errors.rb
mongoid-0.10.1 lib/mongoid/errors.rb
mongoid-0.10.0 lib/mongoid/errors.rb
mongoid-0.9.12 lib/mongoid/errors.rb
mongoid-0.9.11 lib/mongoid/errors.rb
mongoid-0.9.10 lib/mongoid/errors.rb