Skip to content

Commit

Permalink
API CHANGE: moving XGen::Mongo::Driver and XGen::Mongo to Mongo and X…
Browse files Browse the repository at this point in the history
…Gen::Mongo::GridFS to GridFS
  • Loading branch information
Mike Dirolf committed Aug 20, 2009
1 parent 040ba7c commit e65dd99
Show file tree
Hide file tree
Showing 63 changed files with 2,220 additions and 2,352 deletions.
18 changes: 9 additions & 9 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion bin/bson_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'

include XGen::Mongo::Driver
include Mongo

TRIALS = 100000

Expand Down
6 changes: 3 additions & 3 deletions bin/mongo_console
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
6 changes: 3 additions & 3 deletions bin/standard_benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand Down
6 changes: 3 additions & 3 deletions examples/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
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
Expand Down
4 changes: 2 additions & 2 deletions examples/benchmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
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

Expand Down
8 changes: 4 additions & 4 deletions examples/blog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ def errmsg
"%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
end
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
Expand Down
6 changes: 3 additions & 3 deletions examples/capped.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions examples/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
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
Expand Down
8 changes: 4 additions & 4 deletions examples/gridfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
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 }
Expand Down
22 changes: 11 additions & 11 deletions examples/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ def errmsg
"%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
end
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
res = db.drop_collection('test')
puts "dropped : #{res.inspect}"
puts "dropped : #{res.inspect}"
rescue => e
puts "Error: #{e.errmsg}"
end

puts ">> Creating collection test"
begin
coll = db.collection('test')
puts "created : #{coll.inspect}"
puts "created : #{coll.inspect}"
rescue => e
puts "Error: #{e.errmsg}"
end
Expand Down Expand Up @@ -59,8 +59,8 @@ def errmsg

puts ">> Gathering index information"
begin
res = coll.index_information
puts "index_information : #{res.inspect}"
res = coll.index_information
puts "index_information : #{res.inspect}"
rescue => e
puts "Error: #{e.errmsg}"
end
Expand All @@ -76,7 +76,7 @@ def errmsg

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}"
Expand Down Expand Up @@ -105,8 +105,8 @@ def errmsg

puts ">> Gathering index information"
begin
res = coll.index_information
puts "index_information : #{res.inspect}"
res = coll.index_information
puts "index_information : #{res.inspect}"
rescue => e
puts "Error: #{e.errmsg}"
end
Expand Down
6 changes: 3 additions & 3 deletions examples/info.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
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
Expand Down
6 changes: 3 additions & 3 deletions examples/simple.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/strict.rb
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
13 changes: 4 additions & 9 deletions examples/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
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
Expand All @@ -25,13 +25,8 @@
'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)

Expand Down
Loading

0 comments on commit e65dd99

Please sign in to comment.