Skip to content

Commit e65dd99

Browse files
author
Mike Dirolf
committed
API CHANGE: moving XGen::Mongo::Driver and XGen::Mongo to Mongo and XGen::Mongo::GridFS to GridFS
1 parent 040ba7c commit e65dd99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2220
-2352
lines changed

README.rdoc

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ many more.
77

88
require 'mongo'
99

10-
include XGen::Mongo::Driver
10+
include Mongo
1111

12-
db = Mongo.new('localhost').db('sample-db')
12+
db = Mongo::Mongo.new('localhost').db('sample-db')
1313
coll = db.collection('test')
1414

1515
coll.clear
@@ -79,8 +79,8 @@ Here is some simple example code:
7979
require 'rubygems' # not required for Ruby 1.9
8080
require 'mongo'
8181

82-
include XGen::Mongo::Driver
83-
db = Mongo.new.db('my-db-name')
82+
include Mongo
83+
db = Mongo::Mongo.new.db('my-db-name')
8484
things = db.collection('things')
8585

8686
things.clear
@@ -149,8 +149,8 @@ using a PK factory lets you do so.
149149
You can tell the Ruby Mongo driver how to create primary keys by passing in
150150
the :pk option to the Mongo#db method.
151151

152-
include XGen::Mongo::Driver
153-
db = Mongo.new.db('dbname', :pk => MyPKFactory.new)
152+
include Mongo
153+
db = Mongo::Mongo.new.db('dbname', :pk => MyPKFactory.new)
154154

155155
A primary key factory object must respond to :create_pk, which should take a
156156
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:
164164

165165
class TestPKFactory
166166
def create_pk(row)
167-
row['_id'] ||= XGen::Mongo::Driver::ObjectID.new
167+
row['_id'] ||= Mongo::ObjectID.new
168168
row
169169
end
170170
end
@@ -178,7 +178,7 @@ ActiveRecord-like framework for non-Rails apps) and the AR Mongo adapter code
178178
def create_pk(row)
179179
return row if row[:_id]
180180
row.delete(:_id) # in case it exists but the value is nil
181-
row['_id'] ||= XGen::Mongo::Driver::ObjectID.new
181+
row['_id'] ||= Mongo::ObjectID.new
182182
row
183183
end
184184
end
@@ -205,7 +205,7 @@ completely harmless; strict mode is a programmer convenience only.
205205
To turn on strict mode, either pass in :strict => true when obtaining a DB
206206
object or call the :strict= method:
207207

208-
db = XGen::Mongo::Driver::Mongo.new.db('dbname', :strict => true)
208+
db = Mongo::Mongo.new.db('dbname', :strict => true)
209209
# I'm feeling lax
210210
db.strict = false
211211
# No, I'm not!

bin/bson_benchmark.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
44
require 'mongo'
55

6-
include XGen::Mongo::Driver
6+
include Mongo
77

88
TRIALS = 100000
99

bin/mongo_console

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ require 'irb'
77
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
88
require 'mongo'
99

10-
include XGen::Mongo::Driver
10+
include Mongo
1111

1212
host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
13-
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
13+
port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
1414
dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
1515

1616
puts "Connecting to #{host}:#{port} (CONN) on with database #{dbnm} (DB)"
17-
CONN = Mongo.new(host, port)
17+
CONN = Mongo::Mongo.new(host, port)
1818
DB = CONN.db(dbnm)
1919

2020
puts "Starting IRB session..."

bin/standard_benchmark

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
66
require 'mongo'
77

8-
include XGen::Mongo::Driver
8+
include Mongo
99

1010
TRIALS = 2
1111
PER_TRIAL = 5000
@@ -50,9 +50,9 @@ def benchmark(str, proc, n, db, coll_name, object, setup=nil)
5050
end
5151

5252
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
53-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
53+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
5454

55-
connection = Mongo.new(host, port)
55+
connection = Mongo::Mongo.new(host, port)
5656
connection.drop_database("benchmark")
5757
db = connection.db('benchmark')
5858

examples/admin.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
require 'mongo'
33
require 'pp'
44

5-
include XGen::Mongo::Driver
5+
include Mongo
66

77
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
8+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
99

1010
puts "Connecting to #{host}:#{port}"
11-
db = Mongo.new(host, port).db('ruby-mongo-examples')
11+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1212
coll = db.create_collection('test')
1313

1414
# Erase all records from collection, if any

examples/benchmarks.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
require 'mongo'
55

66
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
7+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
88

99
puts "Connecting to #{host}:#{port}"
10-
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-examples')
10+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1111
coll = db.collection('test')
1212
coll.clear
1313

examples/blog.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ def errmsg
55
"%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
66
end
77
end
8-
8+
99
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
1010
require 'mongo'
1111

12-
include XGen::Mongo::Driver
12+
include Mongo
1313

1414
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
15-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
15+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
1616

1717
puts ">> Connecting to #{host}:#{port}"
18-
DB = Mongo.new(host, port).db('ruby-mongo-blog')
18+
DB = Mongo::Mongo.new(host, port).db('ruby-mongo-blog')
1919

2020
LINE_SIZE = 120
2121
puts "=" * LINE_SIZE

examples/capped.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
22
require 'mongo'
33

4-
include XGen::Mongo::Driver
4+
include Mongo
55

66
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
7+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
88

99
puts "Connecting to #{host}:#{port}"
10-
db = Mongo.new(host, port).db('ruby-mongo-examples')
10+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1111
db.drop_collection('test')
1212

1313
# A capped collection has a max size and optionally a max number of records.

examples/cursor.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
require 'mongo'
33
require 'pp'
44

5-
include XGen::Mongo::Driver
5+
include Mongo
66

77
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
8+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
99

1010
puts "Connecting to #{host}:#{port}"
11-
db = Mongo.new(host, port).db('ruby-mongo-examples')
11+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1212
coll = db.collection('test')
1313

1414
# Erase all records from collection, if any

examples/gridfs.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
require 'mongo'
33
require 'mongo/gridfs'
44

5-
include XGen::Mongo::Driver
6-
include XGen::Mongo::GridFS
5+
include Mongo
6+
include GridFS
77

88
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
9-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
9+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
1010

1111
puts "Connecting to #{host}:#{port}"
12-
db = Mongo.new(host, port).db('ruby-mongo-examples')
12+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1313

1414
def dump(db, fname)
1515
GridStore.open(db, fname, 'r') { |f| puts f.read }

examples/index_test.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ def errmsg
33
"%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
44
end
55
end
6-
6+
77
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
88
require 'mongo'
99

10-
include XGen::Mongo::Driver
10+
include Mongo
1111

1212
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
13-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
13+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
1414

1515
puts ">> Connecting to #{host}:#{port}"
16-
db = Mongo.new(host, port).db('ruby-mongo-index_test')
16+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-index_test')
1717

1818
puts ">> Dropping collection test"
1919
begin
2020
res = db.drop_collection('test')
21-
puts "dropped : #{res.inspect}"
21+
puts "dropped : #{res.inspect}"
2222
rescue => e
2323
puts "Error: #{e.errmsg}"
2424
end
2525

2626
puts ">> Creating collection test"
2727
begin
2828
coll = db.collection('test')
29-
puts "created : #{coll.inspect}"
29+
puts "created : #{coll.inspect}"
3030
rescue => e
3131
puts "Error: #{e.errmsg}"
3232
end
@@ -59,8 +59,8 @@ def errmsg
5959

6060
puts ">> Gathering index information"
6161
begin
62-
res = coll.index_information
63-
puts "index_information : #{res.inspect}"
62+
res = coll.index_information
63+
puts "index_information : #{res.inspect}"
6464
rescue => e
6565
puts "Error: #{e.errmsg}"
6666
end
@@ -76,7 +76,7 @@ def errmsg
7676

7777
puts ">> Dropping index"
7878
begin
79-
res = coll.drop_index "all"
79+
res = coll.drop_index "all_1"
8080
puts "dropped : #{res.inspect}"
8181
rescue => e
8282
puts "Error: #{e.errmsg}"
@@ -105,8 +105,8 @@ def errmsg
105105

106106
puts ">> Gathering index information"
107107
begin
108-
res = coll.index_information
109-
puts "index_information : #{res.inspect}"
108+
res = coll.index_information
109+
puts "index_information : #{res.inspect}"
110110
rescue => e
111111
puts "Error: #{e.errmsg}"
112112
end

examples/info.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
22
require 'mongo'
33

4-
include XGen::Mongo::Driver
4+
include Mongo
55

66
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
7+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
88

99
puts "Connecting to #{host}:#{port}"
10-
db = Mongo.new(host, port).db('ruby-mongo-examples')
10+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1111
coll = db.collection('test')
1212

1313
# Erase all records from collection, if any

examples/queries.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
require 'mongo'
33
require 'pp'
44

5-
include XGen::Mongo::Driver
5+
include Mongo
66

77
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
8+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
99

1010
puts "Connecting to #{host}:#{port}"
11-
db = Mongo.new(host, port).db('ruby-mongo-examples')
11+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1212
coll = db.collection('test')
1313

1414
# Remove all records, if any

examples/simple.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
22
require 'mongo'
33

4-
include XGen::Mongo::Driver
4+
include Mongo
55

66
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
7+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
88

99
puts "Connecting to #{host}:#{port}"
10-
db = Mongo.new(host, port).db('ruby-mongo-examples')
10+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1111
coll = db.collection('test')
1212

1313
# Erase all records from collection, if any

examples/strict.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
22
require 'mongo'
33

4-
include XGen::Mongo::Driver
4+
include Mongo
55

66
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
7+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
88

99
puts "Connecting to #{host}:#{port}"
10-
db = Mongo.new(host, port).db('ruby-mongo-examples')
10+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1111

1212
db.drop_collection('does-not-exist')
1313
db.create_collection('test')

examples/types.rb

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
require 'mongo'
33
require 'pp'
44

5-
include XGen::Mongo::Driver
5+
include Mongo
66

77
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
8+
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Mongo::DEFAULT_PORT
99

1010
puts "Connecting to #{host}:#{port}"
11-
db = Mongo.new(host, port).db('ruby-mongo-examples')
11+
db = Mongo::Mongo.new(host, port).db('ruby-mongo-examples')
1212
coll = db.collection('test')
1313

1414
# Remove all records, if any
@@ -25,13 +25,8 @@
2525
'float' => 33.33333,
2626
'regex' => /foobar/i,
2727
'boolean' => true,
28-
'$where' => Code.new('this.x == 3'),
28+
'where' => Code.new('this.x == 3'),
2929
'dbref' => DBRef.new(coll.name, ObjectID.new),
30-
31-
# NOTE: the undefined type is not saved to the database properly. This is a
32-
# Mongo bug. However, the undefined type may go away completely.
33-
# 'undef' => Undefined.new,
34-
3530
'null' => nil,
3631
'symbol' => :zildjian)
3732

0 commit comments

Comments
 (0)