API CHANGE: moving XGen::Mongo::Driver and XGen::Mongo to Mongo and XGen::Mongo::GridFS to GridFS

This commit is contained in:
Mike Dirolf 2009-08-20 10:50:48 -04:00
parent 040ba7c9c2
commit e65dd99667
63 changed files with 2291 additions and 2423 deletions

View File

@ -7,9 +7,9 @@ many more.
require 'mongo'
include XGen::Mongo::Driver
include Mongo
db = Mongo.new('localhost').db('sample-db')
db = Mongo::Mongo.new('localhost').db('sample-db')
coll = db.collection('test')
coll.clear
@ -79,8 +79,8 @@ Here is some simple example code:
require 'rubygems' # not required for Ruby 1.9
require 'mongo'
include XGen::Mongo::Driver
db = Mongo.new.db('my-db-name')
include Mongo
db = Mongo::Mongo.new.db('my-db-name')
things = db.collection('things')
things.clear
@ -149,8 +149,8 @@ using a PK factory lets you do so.
You can tell the Ruby Mongo driver how to create primary keys by passing in
the :pk option to the Mongo#db method.
include XGen::Mongo::Driver
db = Mongo.new.db('dbname', :pk => MyPKFactory.new)
include Mongo
db = Mongo::Mongo.new.db('dbname', :pk => MyPKFactory.new)
A primary key factory object must respond to :create_pk, which should take a
hash and return a hash which merges the original hash with any primary key
@ -164,7 +164,7 @@ Here is a sample primary key factory, taken from the tests:
class TestPKFactory
def create_pk(row)
row['_id'] ||= XGen::Mongo::Driver::ObjectID.new
row['_id'] ||= Mongo::ObjectID.new
row
end
end
@ -178,7 +178,7 @@ ActiveRecord-like framework for non-Rails apps) and the AR Mongo adapter code
def create_pk(row)
return row if row[:_id]
row.delete(:_id) # in case it exists but the value is nil
row['_id'] ||= XGen::Mongo::Driver::ObjectID.new
row['_id'] ||= Mongo::ObjectID.new
row
end
end
@ -205,7 +205,7 @@ completely harmless; strict mode is a programmer convenience only.
To turn on strict mode, either pass in :strict => true when obtaining a DB
object or call the :strict= method:
db = XGen::Mongo::Driver::Mongo.new.db('dbname', :strict => true)
db = Mongo::Mongo.new.db('dbname', :strict => true)
# I'm feeling lax
db.strict = false
# No, I'm not!

View File

@ -3,7 +3,7 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
TRIALS = 100000

View File

@ -7,14 +7,14 @@ require 'irb'
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
puts "Connecting to #{host}:#{port} (CONN) on with database #{dbnm} (DB)"
CONN = Mongo.new(host, port)
CONN = Mongo::Mongo.new(host, port)
DB = CONN.db(dbnm)
puts "Starting IRB session..."

View File

@ -5,7 +5,7 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
TRIALS = 2
PER_TRIAL = 5000
@ -50,9 +50,9 @@ def benchmark(str, proc, n, db, coll_name, object, setup=nil)
end
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
connection = Mongo.new(host, port)
connection = Mongo::Mongo.new(host, port)
connection.drop_database("benchmark")
db = connection.db('benchmark')

View File

@ -2,13 +2,13 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'pp'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
coll = db.create_collection('test')
# Erase all records from collection, if any

View File

@ -4,10 +4,10 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
coll.clear

View File

@ -9,13 +9,13 @@ end
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts ">> Connecting to #{host}:#{port}"
DB = Mongo.new(host, port).db('ruby-mongo-blog')
DB = Mongo::Mongo.new(host, port).db('ruby-mongo-blog')
LINE_SIZE = 120
puts "=" * LINE_SIZE

View File

@ -1,13 +1,13 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
db.drop_collection('test')
# A capped collection has a max size and optionally a max number of records.

View File

@ -2,13 +2,13 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'pp'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Erase all records from collection, if any

View File

@ -2,14 +2,14 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'mongo/gridfs'
include XGen::Mongo::Driver
include XGen::Mongo::GridFS
include Mongo
include GridFS
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
def dump(db, fname)
GridStore.open(db, fname, 'r') { |f| puts f.read }

View File

@ -7,13 +7,13 @@ end
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts ">> Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-index_test')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-index_test')
puts ">> Dropping collection test"
begin
@ -76,7 +76,7 @@ end
puts ">> Dropping index"
begin
res = coll.drop_index "all"
res = coll.drop_index "all_1"
puts "dropped : #{res.inspect}"
rescue => e
puts "Error: #{e.errmsg}"

View File

@ -1,13 +1,13 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Erase all records from collection, if any

View File

@ -2,13 +2,13 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'pp'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Remove all records, if any

View File

@ -1,13 +1,13 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Erase all records from collection, if any

View File

@ -1,13 +1,13 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
db.drop_collection('does-not-exist')
db.create_collection('test')

View File

@ -2,13 +2,13 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'pp'
include XGen::Mongo::Driver
include Mongo
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples')
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
# Remove all records, if any
@ -25,13 +25,8 @@ coll.insert('array' => [1, 2, 3],
'float' => 33.33333,
'regex' => /foobar/i,
'boolean' => true,
'$where' => Code.new('this.x == 3'),
'where' => Code.new('this.x == 3'),
'dbref' => DBRef.new(coll.name, ObjectID.new),
# NOTE: the undefined type is not saved to the database properly. This is a
# Mongo bug. However, the undefined type may go away completely.
# 'undef' => Undefined.new,
'null' => nil,
'symbol' => :zildjian)

View File

@ -275,7 +275,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
case T_STRING:
{
if (strcmp(rb_class2name(RBASIC(value)->klass),
"XGen::Mongo::Driver::Code") == 0) {
"Mongo::Code") == 0) {
int start_position, length_location, length, total_length;
write_name_and_type(buffer, key, 0x0F);
@ -314,7 +314,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
{
// TODO there has to be a better way to do these checks...
const char* cls = rb_class2name(RBASIC(value)->klass);
if (strcmp(cls, "XGen::Mongo::Driver::Binary") == 0 ||
if (strcmp(cls, "Mongo::Binary") == 0 ||
strcmp(cls, "ByteBuffer") == 0) {
const char subtype = strcmp(cls, "ByteBuffer") ?
(const char)FIX2INT(rb_funcall(value, rb_intern("subtype"), 0)) : 2;
@ -333,7 +333,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
buffer_write_bytes(buffer, RSTRING_PTR(string_data), length);
break;
}
if (strcmp(cls, "XGen::Mongo::Driver::ObjectID") == 0) {
if (strcmp(cls, "Mongo::ObjectID") == 0) {
VALUE as_array = rb_funcall(value, rb_intern("to_a"), 0);
int i;
write_name_and_type(buffer, key, 0x07);
@ -343,7 +343,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
}
break;
}
if (strcmp(cls, "XGen::Mongo::Driver::DBRef") == 0) {
if (strcmp(cls, "Mongo::DBRef") == 0) {
int start_position, length_location, obj_length;
VALUE ns, oid;
write_name_and_type(buffer, key, 0x03);
@ -364,7 +364,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
memcpy(buffer->buffer + length_location, &obj_length, 4);
break;
}
if (strcmp(cls, "XGen::Mongo::Driver::Undefined") == 0) {
if (strcmp(cls, "Mongo::Undefined") == 0) {
write_name_and_type(buffer, key, 0x0A); // just use nil type
break;
}
@ -736,25 +736,22 @@ static VALUE method_deserialize(VALUE self, VALUE bson) {
}
void Init_cbson() {
VALUE driver, CBson;
VALUE mongo, CBson;
Time = rb_const_get(rb_cObject, rb_intern("Time"));
driver = rb_const_get(rb_const_get(rb_const_get(rb_cObject,
rb_intern("XGen")),
rb_intern("Mongo")),
rb_intern("Driver"));
mongo = rb_const_get(rb_cObject, rb_intern("Mongo"));
rb_require("mongo/types/binary");
Binary = rb_const_get(driver, rb_intern("Binary"));
Binary = rb_const_get(mongo, rb_intern("Binary"));
rb_require("mongo/types/objectid");
ObjectID = rb_const_get(driver, rb_intern("ObjectID"));
ObjectID = rb_const_get(mongo, rb_intern("ObjectID"));
rb_require("mongo/types/dbref");
DBRef = rb_const_get(driver, rb_intern("DBRef"));
DBRef = rb_const_get(mongo, rb_intern("DBRef"));
rb_require("mongo/types/code");
Code = rb_const_get(driver, rb_intern("Code"));
Code = rb_const_get(mongo, rb_intern("Code"));
rb_require("mongo/types/regexp_of_holding");
RegexpOfHolding = rb_const_get(driver, rb_intern("RegexpOfHolding"));
RegexpOfHolding = rb_const_get(mongo, rb_intern("RegexpOfHolding"));
rb_require("mongo/errors");
InvalidName = rb_const_get(driver, rb_intern("InvalidName"));
InvalidName = rb_const_get(mongo, rb_intern("InvalidName"));
rb_require("mongo/util/ordered_hash");
OrderedHash = rb_const_get(rb_cObject, rb_intern("OrderedHash"));

View File

@ -12,9 +12,7 @@ require 'mongo/cursor'
require 'mongo/collection'
require 'mongo/admin'
module XGen
module Mongo
module Mongo
ASCENDING = 1
DESCENDING = -1
end
end

View File

@ -16,9 +16,7 @@
require 'mongo/util/ordered_hash'
module XGen
module Mongo
module Driver
module Mongo
# Provide administrative database methods: those having to do with
# profiling and validation.
@ -82,6 +80,4 @@ module XGen
end
end
end
end
end

View File

@ -16,9 +16,7 @@
require 'mongo/query'
module XGen
module Mongo
module Driver
module Mongo
# A named collection of records in a database.
class Collection
@ -275,7 +273,7 @@ module XGen
# Create a new index. +field_or_spec+
# should be either a single field name or a Array of [field name,
# direction] pairs. Directions should be specified as
# XGen::Mongo::ASCENDING or XGen::Mongo::DESCENDING.
# Mongo::ASCENDING or Mongo::DESCENDING.
# +unique+ is an optional boolean indicating whether this index
# should enforce a uniqueness constraint.
def create_index(field_or_spec, unique=false)
@ -435,7 +433,4 @@ EOS
end
end
end
end
end
end

View File

@ -18,9 +18,7 @@ require 'mongo/message'
require 'mongo/util/byte_buffer'
require 'mongo/util/bson'
module XGen
module Mongo
module Driver
module Mongo
# A cursor over query results. Returned objects are hashes.
class Cursor
@ -244,6 +242,4 @@ module XGen
"DBResponse(flags=#@result_flags, cursor_id=#@cursor_id, start=#@starting_from, n_returned=#@n_returned)"
end
end
end
end
end

View File

@ -23,9 +23,7 @@ require 'mongo/query'
require 'mongo/util/ordered_hash.rb'
require 'mongo/admin'
module XGen
module Mongo
module Driver
module Mongo
# A Mongo database.
class DB
@ -461,7 +459,7 @@ module XGen
# Create a new index on +collection_name+. +field_or_spec+
# should be either a single field name or a Array of [field name,
# direction] pairs. Directions should be specified as
# XGen::Mongo::ASCENDING or XGen::Mongo::DESCENDING. Normally called
# Mongo::ASCENDING or Mongo::DESCENDING. Normally called
# by Collection#create_index. If +unique+ is true the index will
# enforce a uniqueness constraint.
def create_index(collection_name, field_or_spec, unique=false)
@ -559,6 +557,4 @@ module XGen
return temp.join("_")
end
end
end
end
end

View File

@ -14,14 +14,10 @@
# Exceptions raised by the MongoDB driver.
module XGen
module Mongo
module Driver
module Mongo
# Raised when a database operation fails.
class OperationFailure < RuntimeError; end
# Raised when an invalid name is used.
class InvalidName < RuntimeError; end
end
end
end

View File

@ -19,9 +19,7 @@ require 'mongo/util/byte_buffer'
require 'mongo/util/ordered_hash'
module XGen
module Mongo
module GridFS
module GridFS
# A chunk stores a portion of GridStore data.
class Chunk
@ -33,7 +31,7 @@ module XGen
def initialize(file, mongo_object={})
@file = file
@object_id = mongo_object['_id'] || XGen::Mongo::Driver::ObjectID.new
@object_id = mongo_object['_id'] || Mongo::ObjectID.new
@chunk_number = mongo_object['n'] || 0
@data = ByteBuffer.new
@ -91,6 +89,4 @@ module XGen
end
end
end
end
end

View File

@ -18,9 +18,7 @@ require 'mongo/types/objectid'
require 'mongo/util/ordered_hash'
require 'mongo/gridfs/chunk'
module XGen
module Mongo
module GridFS
module GridFS
# GridStore is an IO-like object that provides input and output for
# streams of data to Mongo. See Mongo's documentation about GridFS for
@ -158,7 +156,7 @@ module XGen
@metadata = doc['metadata']
@md5 = doc['md5']
else
@files_id = XGen::Mongo::Driver::ObjectID.new
@files_id = Mongo::ObjectID.new
@content_type = DEFAULT_CONTENT_TYPE
@chunk_size = Chunk::DEFAULT_CHUNK_SIZE
@length = 0
@ -169,7 +167,7 @@ module XGen
@curr_chunk = nth_chunk(0)
@position = 0
when 'w'
chunk_collection.create_index([['files_id', XGen::Mongo::ASCENDING], ['n', XGen::Mongo::ASCENDING]])
chunk_collection.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]])
delete_chunks
@curr_chunk = Chunk.new(self, 'n' => 0)
@content_type = options[:content_type] if options[:content_type]
@ -177,7 +175,7 @@ module XGen
@metadata = options[:metadata] if options[:metadata]
@position = 0
when 'w+'
chunk_collection.create_index([['files_id', XGen::Mongo::ASCENDING], ['n', XGen::Mongo::ASCENDING]])
chunk_collection.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]])
@curr_chunk = nth_chunk(last_chunk_number) || Chunk.new(self, 'n' => 0) # might be empty
@curr_chunk.pos = @curr_chunk.data.length if @curr_chunk
@metadata = options[:metadata] if options[:metadata]
@ -463,6 +461,4 @@ module XGen
end
end
end
end
end

View File

@ -17,9 +17,7 @@
require 'mongo/message/message'
require 'mongo/message/opcodes'
module XGen
module Mongo
module Driver
module Mongo
class GetMoreMessage < Message
@ -31,7 +29,4 @@ module XGen
write_long(cursor)
end
end
end
end
end

View File

@ -17,9 +17,7 @@
require 'mongo/message/message'
require 'mongo/message/opcodes'
module XGen
module Mongo
module Driver
module Mongo
class InsertMessage < Message
@ -30,6 +28,4 @@ module XGen
objs.each { |o| write_doc(o, check_keys) }
end
end
end
end
end

View File

@ -17,9 +17,7 @@
require 'mongo/message/message'
require 'mongo/message/opcodes'
module XGen
module Mongo
module Driver
module Mongo
class KillCursorsMessage < Message
@ -30,7 +28,4 @@ module XGen
cursors.each { |c| write_long c }
end
end
end
end
end

View File

@ -17,9 +17,7 @@
require 'mongo/util/bson'
require 'mongo/util/byte_buffer'
module XGen
module Mongo
module Driver
module Mongo
class Message
@ -79,6 +77,4 @@ module XGen
end
end
end
end
end

View File

@ -16,9 +16,7 @@
require 'mongo/util/byte_buffer'
module XGen
module Mongo
module Driver
module Mongo
class MessageHeader
@ -44,7 +42,4 @@ module XGen
@buf.dump
end
end
end
end
end

View File

@ -17,9 +17,7 @@
require 'mongo/message/message'
require 'mongo/message/opcodes'
module XGen
module Mongo
module Driver
module Mongo
class MsgMessage < Message
@ -28,6 +26,4 @@ module XGen
write_string(msg)
end
end
end
end
end

View File

@ -14,9 +14,7 @@
# limitations under the License.
# ++
module XGen
module Mongo
module Driver
module Mongo
OP_REPLY = 1 # reply. responseTo is set.
OP_MSG = 1000 # generic msg command followed by a string
OP_UPDATE = 2001 # update object
@ -26,7 +24,4 @@ module XGen
OP_GET_MORE = 2005
OP_DELETE = 2006
OP_KILL_CURSORS = 2007
end
end
end

View File

@ -18,9 +18,7 @@ require 'mongo/message/message'
require 'mongo/message/opcodes'
require 'mongo/util/ordered_hash'
module XGen
module Mongo
module Driver
module Mongo
class QueryMessage < Message
@ -72,6 +70,4 @@ module XGen
@first_key = key
end
end
end
end
end

View File

@ -17,9 +17,7 @@
require 'mongo/message/message'
require 'mongo/message/opcodes'
module XGen
module Mongo
module Driver
module Mongo
class RemoveMessage < Message
@ -31,6 +29,4 @@ module XGen
write_doc(sel)
end
end
end
end
end

View File

@ -17,9 +17,7 @@
require 'mongo/message/message'
require 'mongo/message/opcodes'
module XGen
module Mongo
module Driver
module Mongo
class UpdateMessage < Message
@ -32,6 +30,4 @@ module XGen
write_doc(obj)
end
end
end
end
end

View File

@ -16,9 +16,7 @@
require 'mongo/db'
module XGen
module Mongo
module Driver
module Mongo
# Represents a Mongo database server.
class Mongo
@ -87,11 +85,11 @@ module XGen
@options = options
end
# Return the XGen::Mongo::Driver::DB named +db_name+. The slave_ok and
# Return the Mongo::DB named +db_name+. The slave_ok and
# auto_reconnect options passed in via #new may be overridden here.
# See DB#new for other options you can pass in.
def db(db_name, options={})
XGen::Mongo::Driver::DB.new(db_name, @pair, @options.merge(options))
DB.new(db_name, @pair, @options.merge(options))
end
# Returns a hash containing database names as keys and disk space for
@ -158,7 +156,4 @@ module XGen
end
end
end
end
end

View File

@ -18,9 +18,7 @@ require 'mongo/collection'
require 'mongo/message'
require 'mongo/types/code'
module XGen
module Mongo
module Driver
module Mongo
# A query against a collection. A query's selector is a hash. See the
# Mongo documentation for query details.
@ -114,6 +112,4 @@ module XGen
(@order_by != nil && @order_by.length > 0) || @explain || @hint || @snapshot
end
end
end
end
end

View File

@ -16,9 +16,7 @@
require 'mongo/util/byte_buffer'
module XGen
module Mongo
module Driver
module Mongo
# An array of binary bytes with a Mongo subtype value.
class Binary < ByteBuffer
@ -37,6 +35,4 @@ module XGen
end
end
end
end
end

View File

@ -14,9 +14,7 @@
# limitations under the License.
# ++
module XGen
module Mongo
module Driver
module Mongo
# JavaScript code to be evaluated by MongoDB
class Code < String
@ -29,6 +27,4 @@ module XGen
end
end
end
end
end

View File

@ -14,9 +14,7 @@
# limitations under the License.
# ++
module XGen
module Mongo
module Driver
module Mongo
class DBRef
@ -32,6 +30,4 @@ module XGen
end
end
end
end
end

View File

@ -17,9 +17,7 @@
require 'mutex_m'
require 'mongo/util/byte_buffer'
module XGen
module Mongo
module Driver
module Mongo
# Implementation of the Babble OID. Object ids are not required by
# Mongo, but they make certain operations more efficient.
@ -132,6 +130,4 @@ module XGen
end
end
end
end
end

View File

@ -14,9 +14,7 @@
# limitations under the License.
# ++
module XGen
module Mongo
module Driver
module Mongo
# A Regexp that can hold on to extra options and ignore them. Mongo
# regexes may contain option characters beyond 'i', 'm', and 'x'. (Note
@ -39,6 +37,4 @@ module XGen
end
end
end
end
end

View File

@ -14,9 +14,7 @@
# limitations under the License.
# ++
module XGen
module Mongo
module Driver
module Mongo
# DEPRECATED - the ruby driver converts the BSON undefined type to nil,
# and saves this type as nil
@ -27,6 +25,4 @@ module XGen
warn "the Undefined type is deprecated and will be removed - BSON undefineds get implicitely converted to nil now"
end
end
end
end
end

View File

@ -26,7 +26,7 @@ require 'mongo/types/undefined'
# A BSON seralizer/deserializer.
class BSON
include XGen::Mongo::Driver
include Mongo
MINKEY = -1
EOO = 0

View File

@ -21,7 +21,7 @@ require 'mongo'
# an OrderedHash.
class XMLToRuby
include XGen::Mongo::Driver
include Mongo
def xml_to_ruby(io)
doc = REXML::Document.new(io)

View File

@ -5,4 +5,4 @@ DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 27017
DEFAULT_DB = 'driver_test_framework'
include XGen::Mongo::Driver
include Mongo

View File

@ -3,9 +3,9 @@
require File.join(File.dirname(__FILE__), '_common.rb')
require 'mongo/gridfs'
include XGen::Mongo::GridFS
include GridFS
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
db = Mongo::Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
input_file = ARGV[0]

View File

@ -3,9 +3,9 @@
require File.join(File.dirname(__FILE__), '_common.rb')
require 'mongo/gridfs'
include XGen::Mongo::GridFS
include GridFS
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
db = Mongo::Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
input_file = ARGV[0]
output_file = ARGV[1]

View File

@ -2,9 +2,9 @@
require File.join(File.dirname(__FILE__), '_common.rb')
include XGen::Mongo
include Mongo
db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
db = Mongo::Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
x = db.collection('x')
y = db.collection('y')

View File

@ -5,7 +5,7 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class AdminTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
@@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')

View File

@ -5,7 +5,7 @@ require 'test/unit'
class BSONTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
def setup
# We don't pass a DB to the constructor, even though we are about to test
@ -85,7 +85,7 @@ class BSONTest < Test::Unit::TestCase
assert_equal doc, doc2
r = doc2['doc']
assert_kind_of XGen::Mongo::Driver::RegexpOfHolding, r
assert_kind_of RegexpOfHolding, r
assert_equal '', r.extra_options_str
r.extra_options_str << 'zywcab'
@ -99,7 +99,7 @@ class BSONTest < Test::Unit::TestCase
assert_equal doc, doc2
r = doc2['doc']
assert_kind_of XGen::Mongo::Driver::RegexpOfHolding, r
assert_kind_of RegexpOfHolding, r
assert_equal 'abcwyz', r.extra_options_str # must be sorted
end

View File

@ -5,8 +5,8 @@ require 'mongo/gridfs'
class ChunkTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include XGen::Mongo::GridFS
include Mongo
include GridFS
@@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-utils-test')

View File

@ -20,8 +20,7 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class TestCollection < Test::Unit::TestCase
include XGen::Mongo
include XGen::Mongo::Driver
include Mongo
@@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')

View File

@ -5,7 +5,7 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class CursorTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
@@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')

View File

@ -5,7 +5,7 @@ require 'test/unit'
class TestPKFactory
def create_pk(row)
row['_id'] ||= XGen::Mongo::Driver::ObjectID.new
row['_id'] ||= Mongo::ObjectID.new
row
end
end
@ -13,7 +13,7 @@ end
# NOTE: assumes Mongo is running
class DBTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
@@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
@@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
@ -85,7 +85,7 @@ class DBTest < Test::Unit::TestCase
assert_not_nil oid
assert_equal insert_id, oid
oid = XGen::Mongo::Driver::ObjectID.new
oid = ObjectID.new
data = {'_id' => oid, 'name' => 'Barney', 'age' => 41}
coll.insert(data)
row = coll.find_one({'name' => data['name']})

View File

@ -4,8 +4,7 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class DBAPITest < Test::Unit::TestCase
include XGen::Mongo
include XGen::Mongo::Driver
include Mongo
@@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')
@ -817,18 +816,4 @@ class DBAPITest < Test::Unit::TestCase
@@db.collection("test").find({}, :snapshot => true, :sort => 'a').to_a
end
end
# TODO this test fails with error message "Undefed Before end of object"
# That is a database error. The undefined type may go away.
# def test_insert_undefined
# doc = {'undef' => Undefined.new}
# @@coll.clear
# @@coll.insert(doc)
# p @@db.error # DEBUG
# assert_equal 1, @@coll.count
# row = @@coll.find().next_object
# assert_not_nil row
# end
end

View File

@ -5,7 +5,7 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class DBConnectionTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
def test_no_exceptions
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'

View File

@ -5,8 +5,8 @@ require 'mongo/gridfs'
class GridStoreTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include XGen::Mongo::GridFS
include Mongo
include GridFS
@@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')

View File

@ -4,7 +4,7 @@ require 'test/unit'
class MessageTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
def setup
@msg = Message.new(42)

View File

@ -5,7 +5,7 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class MongoTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
def setup
@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'

View File

@ -4,7 +4,7 @@ require 'test/unit'
class ObjectIDTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
def setup
@t = 42

View File

@ -13,7 +13,7 @@ require 'test/unit'
# of this project), then we find the BSON test files there and use those, too.
class RoundTripTest < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
@@ruby = nil

View File

@ -4,7 +4,7 @@ require 'test/unit'
class TestThreading < Test::Unit::TestCase
include XGen::Mongo::Driver
include Mongo
@@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
@@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT