minor: reorganized constants / errors

This commit is contained in:
Kyle Banker 2010-01-08 15:43:13 -05:00
parent 4024a5b333
commit 5285f9de8f
6 changed files with 79 additions and 95 deletions

View File

@ -1,9 +1,6 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
module Mongo
ASCENDING = 1
DESCENDING = -1
VERSION = "0.18.2"
end
@ -23,6 +20,68 @@ begin
warn " mongo_ext gem is in your load path and that the mongo_ext and mongo gems are of the same version.\n"
end
module Mongo
ASCENDING = 1
DESCENDING = -1
module Constants
OP_REPLY = 1
OP_MSG = 1000
OP_UPDATE = 2001
OP_INSERT = 2002
OP_QUERY = 2004
OP_GET_MORE = 2005
OP_DELETE = 2006
OP_KILL_CURSORS = 2007
OP_QUERY_SLAVE_OK = 4
OP_QUERY_NO_CURSOR_TIMEOUT = 16
end
# Generic Mongo Ruby Driver exception class.
class MongoRubyError < StandardError; end
# Raised when MongoDB itself has returned an error.
class MongoDBError < RuntimeError; end
# Raised when configuration options cause connections, queries, etc., to fail.
class ConfigurationError < MongoRubyError; end
# Raised when invalid arguments are sent to Mongo Ruby methods.
class MongoArgumentError < MongoRubyError; end
# Raised when given a string is not valid utf-8 (Ruby 1.8 only).
class InvalidStringEncoding < MongoRubyError; end
# Raised when attempting to initialize an invalid ObjectID.
class InvalidObjectID < MongoRubyError; end
# Raised on failures in connection to the database server.
class ConnectionError < MongoRubyError; end
# Raised on failures in connection to the database server.
class ConnectionTimeoutError < MongoRubyError; end
# Raised when trying to insert a document that exceeds the 4MB limit or
# when the document contains objects that can't be serialized as BSON.
class InvalidDocument < MongoDBError; end
# Raised when a database operation fails.
class OperationFailure < MongoDBError; end
# Raised when a connection operation fails.
class ConnectionFailure < MongoDBError; end
# Raised when a client attempts to perform an invalid operation.
class InvalidOperation < MongoDBError; end
# Raised when an invalid name is used.
class InvalidName < RuntimeError; end
# Raised when the client supplies an invalid value to sort by.
class InvalidSortValueError < MongoRubyError; end
end
require 'mongo/types/binary'
require 'mongo/types/code'
require 'mongo/types/dbref'
@ -34,8 +93,6 @@ require 'mongo/util/conversions'
require 'mongo/util/server_version'
require 'mongo/util/bson_ruby'
require 'mongo/errors'
require 'mongo/constants'
require 'mongo/connection'
require 'mongo/db'
require 'mongo/cursor'

View File

@ -234,13 +234,12 @@ module Mongo
# @param [Hash] selector
# If specified, only matching documents will be removed.
#
# Examples
# @example: remove all documents from the 'users':
# @users.remove
# @users.remove({})
# @example remove all documents from the 'users' collection:
# users.remove
# users.remove({})
#
# @example: remove only documents that have expired:
# @users.remove({:expire => {'$lte' => Time.now}})
# @example remove only documents that have expired:
# users.remove({:expire => {"$lte" => Time.now}})
def remove(selector={})
message = ByteBuffer.new
message.put_int(0)
@ -495,8 +494,8 @@ EOS
# @collection.distinct("name.age")
# [27, 24]
#
# You may also pass a document selector as the second parameter
# to limit the documents over which distinct is run:
# # You may also pass a document selector as the second parameter
# # to limit the documents over which distinct is run:
# @collection.distinct("name.age", {"name.age" => {"$gt" => 24}})
# [27]
#

View File

@ -45,11 +45,14 @@ module Mongo
# If connecting to just one server, you may specify whether connection to slave is permitted.
# In all cases, the default host is "localhost" and the default port is 27017.
#
# When specifying a pair, pair_or_host, is a hash with two keys: :left and :right. Each key maps to either
# When specifying a pair, +pair_or_host+, is a hash with two keys: :left and :right. Each key maps to either
# * a server name, in which case port is 27017,
# * a port number, in which case the server is "localhost", or
# * an array containing [server_name, port_number]
#
# Note that there are a few issues when using connection pooling with Ruby 1.9 on Windows. These
# should be resolved in the next release.
#
# @param [String, Hash] pair_or_host See explanation above.
# @param [Integer] port specify a port number here if only one host is being specified. Leave nil if
# specifying a pair of servers in +pair_or_host+.
@ -62,8 +65,6 @@ module Mongo
# @option options [Float] :timeout (5.0) When all of the connections to the pool are checked out,
# this is the number of seconds to wait for a new connection to be released before throwing an exception.
#
# @example Note that there are a few issues when using connection pooling with Ruby 1.9 on Windows. These
# should be resolved in the next release.
#
# @example localhost, 27017
# Connection.new
@ -79,7 +80,6 @@ module Mongo
#
# @example A pair of servers. The driver will always talk to master.
# # On connection errors, Mongo::ConnectionFailure will be raised.
# @see http://www.mongodb.org/display/DOCS/Replica+Pairs+in+Ruby Replica pairs in Ruby
# Connection.new({:left => ["db1.example.com", 27017],
# :right => ["db2.example.com", 27017]})
#
@ -87,6 +87,8 @@ module Mongo
# Connection.new({:left => ["db1.example.com", 27017],
# :right => ["db2.example.com", 27017]}, nil,
# :pool_size => 20, :timeout => 5)
#
# @see http://www.mongodb.org/display/DOCS/Replica+Pairs+in+Ruby Replica pairs in Ruby
def initialize(pair_or_host=nil, port=nil, options={})
@nodes = format_pair(pair_or_host, port)

View File

@ -1,15 +0,0 @@
module Mongo
module Constants
OP_REPLY = 1
OP_MSG = 1000
OP_UPDATE = 2001
OP_INSERT = 2002
OP_QUERY = 2004
OP_GET_MORE = 2005
OP_DELETE = 2006
OP_KILL_CURSORS = 2007
OP_QUERY_SLAVE_OK = 4
OP_QUERY_NO_CURSOR_TIMEOUT = 16
end
end

View File

@ -1,60 +0,0 @@
# Copyright 2009 10gen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Exceptions raised by the MongoDB driver.
module Mongo
# Generic Mongo Ruby Driver exception class.
class MongoRubyError < StandardError; end
# Raised when MongoDB itself has returned an error.
class MongoDBError < RuntimeError; end
# Raised when configuration options cause connections, queries, etc., to fail.
class ConfigurationError < MongoRubyError; end
# Raised when invalid arguments are sent to Mongo Ruby methods.
class MongoArgumentError < MongoRubyError; end
# Raised when given a string is not valid utf-8 (Ruby 1.8 only).
class InvalidStringEncoding < MongoRubyError; end
# Raised when attempting to initialize an invalid ObjectID.
class InvalidObjectID < MongoRubyError; end
# Raised on failures in connection to the database server.
class ConnectionError < MongoRubyError; end
# Raised on failures in connection to the database server.
class ConnectionTimeoutError < MongoRubyError; end
# Raised when trying to insert a document that exceeds the 4MB limit or
# when the document contains objects that can't be serialized as BSON.
class InvalidDocument < MongoDBError; end
# Raised when a database operation fails.
class OperationFailure < MongoDBError; end
# Raised when a connection operation fails.
class ConnectionFailure < MongoDBError; end
# Raised when a client attempts to perform an invalid operation.
class InvalidOperation < MongoDBError; end
# Raised when an invalid name is used.
class InvalidName < RuntimeError; end
# Raised when the client supplies an invalid value to sort by.
class InvalidSortValueError < MongoRubyError; end
end

View File

@ -13,10 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ++
# nodoc
#:nodoc:
class Object
# nodoc
#:nodoc:
def returning(value)
yield value
value