minor: db class cleanup

This commit is contained in:
Kyle Banker 2010-01-08 19:11:49 -05:00
parent 74c9862fc9
commit 3a6865e172
2 changed files with 22 additions and 13 deletions

View File

@ -21,7 +21,7 @@ require 'thread'
module Mongo module Mongo
# A Mongo database. # A MongoDB database.
class DB class DB
SYSTEM_NAMESPACE_COLLECTION = "system.namespaces" SYSTEM_NAMESPACE_COLLECTION = "system.namespaces"
@ -55,15 +55,7 @@ module Mongo
# The logger instance if :logger is passed to initialize. # The logger instance if :logger is passed to initialize.
attr_reader :logger attr_reader :logger
# The primary key factory object (or +nil+). # Instances of DB are normally obtained by calling Mongo#db.
attr_reader :pk_factory
def pk_factory=(pk_factory)
raise "error: can not change PK factory" if @pk_factory
@pk_factory = pk_factory
end
# Instances of DB are normally obtained by calling Mongo#db.
# #
# db_name :: The database name # db_name :: The database name
# #
@ -122,7 +114,8 @@ module Mongo
# Deauthorizes use for this database for this connection. # Deauthorizes use for this database for this connection.
def logout def logout
doc = command(:logout => 1) doc = command(:logout => 1)
raise "error logging out: #{doc.inspect}" unless ok?(doc) return true if ok?(doc)
raise "error logging out: #{doc.inspect}"
end end
# Returns an array of collection names in this database. # Returns an array of collection names in this database.
@ -378,6 +371,22 @@ module Mongo
"#{@name}.#{collection_name}" "#{@name}.#{collection_name}"
end end
# The primary key factory object (or +nil+).
def pk_factory
@pk_factory
end
# Specify a primary key factory if not already set.
#
# @raise [MongoArgumentError] if the primary key factory has already been set.
def pk_factory=(pk_factory)
if @pk_factory
raise MongoArgumentError, "Cannot change primary key factory once it's been set"
end
@pk_factory = pk_factory
end
# Return the current database profiling level. # Return the current database profiling level.
# #
# @return [Symbol] :off, :slow_only, or :all # @return [Symbol] :off, :slow_only, or :all

View File

@ -132,7 +132,7 @@ class DBTest < Test::Unit::TestCase
db.pk_factory = Object.new db.pk_factory = Object.new
fail "error: expected exception" fail "error: expected exception"
rescue => ex rescue => ex
assert_match /can not change PK factory/, ex.to_s assert_match /Cannot change/, ex.to_s
ensure ensure
conn.close conn.close
end end
@ -145,7 +145,7 @@ class DBTest < Test::Unit::TestCase
end end
def test_logout def test_logout
@@db.logout # only testing that we don't throw exception assert @@db.logout
end end
def test_error def test_error