Skip to content

Commit

Permalink
minor: reorganized constants / errors
Browse files Browse the repository at this point in the history
  • Loading branch information
banker committed Jan 8, 2010
1 parent 4024a5b commit 5285f9d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 95 deletions.
67 changes: 62 additions & 5 deletions lib/mongo.rb
@@ -1,9 +1,6 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

module Mongo
ASCENDING = 1
DESCENDING = -1

VERSION = "0.18.2"
end

Expand All @@ -23,6 +20,68 @@ module Mongo
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'
Expand All @@ -34,8 +93,6 @@ module Mongo
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'
Expand Down
15 changes: 7 additions & 8 deletions lib/mongo/collection.rb
Expand Up @@ -234,13 +234,12 @@ def insert(doc_or_docs, options={})
# @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)
Expand Down Expand Up @@ -495,8 +494,8 @@ def group(key, condition, initial, reduce, command=false, finalize=nil)
# @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]
#
Expand Down
12 changes: 7 additions & 5 deletions lib/mongo/connection.rb
Expand Up @@ -45,11 +45,14 @@ def slave_ok?
# 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+.
Expand All @@ -62,8 +65,6 @@ def slave_ok?
# @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
Expand All @@ -78,15 +79,16 @@ def slave_ok?
# Connection.new("localhost", 3000, :slave_ok => true)
#
# @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
# # On connection errors, Mongo::ConnectionFailure will be raised.
# Connection.new({:left => ["db1.example.com", 27017],
# :right => ["db2.example.com", 27017]})
#
# @example A pair of servers with connection pooling enabled. Note the nil param placeholder for port.
# 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)

Expand Down
15 changes: 0 additions & 15 deletions lib/mongo/constants.rb

This file was deleted.

60 changes: 0 additions & 60 deletions lib/mongo/errors.rb

This file was deleted.

5 changes: 3 additions & 2 deletions lib/mongo/util/support.rb
Expand Up @@ -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
Expand Down

0 comments on commit 5285f9d

Please sign in to comment.