Skip to content

Commit 81f3314

Browse files
committed
Cleaning up module includes and namespace refs
1 parent 5be9f6a commit 81f3314

19 files changed

+45
-36
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](https://githu
4747
require 'rubygems'
4848
require 'mongo'
4949

50-
@client = Mongo::MongoClient.new('localhost', 27017)
50+
include Mongo
51+
52+
@client = MongoClient.new('localhost', 27017)
5153
@db = @client['sample-db']
5254
@coll = @db['test']
5355

@@ -207,7 +209,8 @@ You can tell the Ruby Mongo driver how to create primary keys by passing in
207209
the :pk option to the MongoClient#db method.
208210

209211
```ruby
210-
db = Mongo::MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
212+
include Mongo
213+
db = MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
211214
```
212215

213216
A primary key factory object must respond to :create_pk, which should

examples/admin.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
1010

1111
puts "Connecting to #{host}:#{port}"
12-
client = Mongo::MongoClient.new(host, port)
12+
client = MongoClient.new(host, port)
1313
db = client.db('ruby-mongo-examples')
1414
coll = db.create_collection('test')
1515

examples/replica_set.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# This code assumes a running replica set with at least one node at localhost:27017.
22
require 'mongo'
33

4+
include Mongo
5+
46
cons = []
57

68
10.times do
7-
cons << Mongo::MongoReplicaSetClient(['localhost:27017'], :read => :secondary)
9+
cons << MongoReplicaSetClient(['localhost:27017'], :read => :secondary)
810
end
911

1012
ports = cons.map do |con|

examples/web/thin/load.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'mongo')
22
require 'logger'
33

4-
$con = Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary, :refresh_mode => :sync, :refresh_interval => 30)
4+
include Mongo
5+
6+
$con = MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary, :refresh_mode => :sync, :refresh_interval => 30)
57
$db = $con['foo']
68

79
class Load < Sinatra::Base

examples/web/unicorn/load.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mongo')
1+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mongo')
22

3-
$client = Mongo::MongoClient.new('localhost', 27017)
3+
include Mongo
4+
5+
$client = MongoClient.new('localhost', 27017)
46
$db = $client['foo']
57

68
class Load < Sinatra::Base

lib/mongo/mongo_client.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ class MongoClient
9595
# @option opts [Boolean] :ssl (false) If true, create the connection to the server using SSL.
9696
#
9797
# @example localhost, 27017 (or <code>ENV["MONGODB_URI"]</code> if available)
98-
# Mongo::MongoClient.new
98+
# MongoClient.new
9999
#
100100
# @example localhost, 27017
101-
# Mongo::MongoClient.new("localhost")
101+
# MongoClient.new("localhost")
102102
#
103103
# @example localhost, 3000, max 5 self.connections, with max 5 seconds of wait time.
104-
# Mongo::MongoClient.new("localhost", 3000, :pool_size => 5, :timeout => 5)
104+
# MongoClient.new("localhost", 3000, :pool_size => 5, :timeout => 5)
105105
#
106106
# @example localhost, 3000, where this node may be a slave
107-
# Mongo::MongoClient.new("localhost", 3000, :slave_ok => true)
107+
# MongoClient.new("localhost", 3000, :slave_ok => true)
108108
#
109109
# @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
110110
#

lib/mongo/mongo_replica_set_client.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ class MongoReplicaSetClient < MongoClient
9494
# The purpose of seed nodes is to permit the driver to find at least one replica set member even if a member is down.
9595
#
9696
# @example Connect to a replica set and provide two seed nodes.
97-
# Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'])
97+
# MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'])
9898
#
9999
# @example Connect to a replica set providing two seed nodes and ensuring a connection to the replica set named 'prod':
100-
# Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :name => 'prod')
100+
# MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :name => 'prod')
101101
#
102102
# @example Connect to a replica set providing two seed nodes and allowing reads from a secondary node:
103-
# Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary)
103+
# MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary)
104104
#
105105
# @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
106106
#

lib/mongo/mongo_sharded_client.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MongoShardedClient < MongoReplicaSetClient
5858
# The purpose of seed nodes is to permit the driver to find at least one sharded cluster member even if a member is down.
5959
#
6060
# @example Connect to a sharded cluster and provide two seed nodes.
61-
# Mongo::MongoShardedClient.new(['localhost:30000', 'localhost:30001'])
61+
# MongoShardedClient.new(['localhost:30000', 'localhost:30001'])
6262
#
6363
# @raise [MongoArgumentError] This is raised for usage errors.
6464
#

lib/mongo/util/uri_parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def port
179179
nodes[0][1].to_i
180180
end
181181

182-
# Options that can be passed to Mongo::MongoClient.new or Mongo::MongoReplicaSetClient.new
182+
# Options that can be passed to MongoClient.new or MongoReplicaSetClient.new
183183
# @return [Hash]
184184
def connection_options
185185
opts = {}

test/auxillary/1.4_feature_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Features14Test < Test::Unit::TestCase
77

88
context "MongoDB 1.4" do
99
setup do
10-
@client = Mongo::MongoClient.new
10+
@client = MongoClient.new
1111
@db = @client['mongo-ruby-test']
1212
@col = @db['new-features']
1313
end

test/auxillary/authentication_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class AuthenticationTest < Test::Unit::TestCase
77
include Mongo
88

99
def setup
10-
@client = Mongo::MongoClient.new
10+
@client = MongoClient.new
1111
@db1 = @client.db('mongo-ruby-test-auth1')
1212
@db2 = @client.db('mongo-ruby-test-auth2')
1313
@admin = @client.db('admin')

test/auxillary/autoreconnect_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AutoreconnectTest < Test::Unit::TestCase
66
include Mongo
77

88
def setup
9-
@client = Mongo::MongoClient.new
9+
@client = MongoClient.new
1010
@db = @client.db('mongo-ruby-test')
1111
@db.drop_collection("test-connect")
1212
@coll = @db.collection("test-connect")

test/functional/connection_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def teardown
1818

1919
def test_connection_failure
2020
assert_raise Mongo::ConnectionFailure do
21-
Mongo::MongoClient.new('localhost', 27347)
21+
MongoClient.new('localhost', 27347)
2222
end
2323
end
2424

test/functional/db_connection_test.rb

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
class DBConnectionTest < Test::Unit::TestCase
44

5-
include Mongo
6-
75
def test_no_exceptions
86
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
97
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT

test/replica_set/basic_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ def self.shutdown
1212
end
1313

1414
def test_connect
15-
client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
15+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
1616
assert client.connected?
1717
assert_equal @rs.primary_name, client.primary.join(':')
1818
assert_equal @rs.secondary_names.sort, client.secondaries.collect{|s| s.join(':')}.sort
1919
assert_equal @rs.arbiter_names.sort, client.arbiters.collect{|s| s.join(':')}.sort
2020
client.close
2121

2222
silently do
23-
client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds_old, :name => @rs.repl_set_name)
23+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds_old, :name => @rs.repl_set_name)
2424
end
2525

2626
assert client.connected?
2727
client.close
2828
end
2929

3030
def test_safe_option
31-
client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
31+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
3232
assert client.connected?
3333
assert client.write_concern[:w] > 0
3434
client.close
35-
client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 0)
35+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 0)
3636
assert client.connected?
3737
assert client.write_concern[:w] < 1
3838
client.close
39-
client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 2)
39+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 2)
4040
assert client.connected?
4141
assert client.write_concern[:w] > 0
4242
client.close

test/replica_set/cursor_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_cursors_get_closed
2525

2626
def setup_client(read=:primary)
2727
# Setup ReplicaSet Connection
28-
@client = Mongo::MongoReplicaSetClient.new(
28+
@client = MongoReplicaSetClient.new(
2929
@rs.repl_set_seeds,
3030
:read => read
3131
)

test/sharded_cluster/basic_test.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'test_helper'
2+
include Mongo
23

34
class BasicTest < Test::Unit::TestCase
5+
46
def setup
57
ensure_cluster(:sc)
68
end
@@ -13,7 +15,7 @@ def self.shutdown
1315
# TODO member.primary? ==> true
1416
def test_connect
1517
seeds = @sc.mongos_seeds
16-
@client = Mongo::MongoShardedClient.new(seeds)
18+
@client = MongoShardedClient.new(seeds)
1719
assert @client.connected?
1820
assert_equal(seeds.size, @client.seeds.size)
1921
probe(seeds.size)
@@ -22,7 +24,7 @@ def test_connect
2224

2325
def test_hard_refresh
2426
seeds = @sc.mongos_seeds
25-
@client = Mongo::MongoShardedClient.new(seeds)
27+
@client = MongoShardedClient.new(seeds)
2628
assert @client.connected?
2729
@client.hard_refresh!
2830
assert @client.connected?
@@ -31,7 +33,7 @@ def test_hard_refresh
3133

3234
def test_reconnect
3335
seeds = @sc.mongos_seeds
34-
@client = Mongo::MongoShardedClient.new(seeds)
36+
@client = MongoShardedClient.new(seeds)
3537
assert @client.connected?
3638
router = @sc.servers(:routers).first
3739
router.stop
@@ -42,7 +44,7 @@ def test_reconnect
4244

4345
def test_all_down
4446
seeds = @sc.mongos_seeds
45-
@client = Mongo::MongoShardedClient.new(seeds)
47+
@client = MongoShardedClient.new(seeds)
4648
assert @client.connected?
4749
@sc.servers(:routers).each{|router| router.stop}
4850
assert_raises Mongo::ConnectionFailure do
@@ -54,7 +56,7 @@ def test_all_down
5456

5557
def test_cycle
5658
seeds = @sc.mongos_seeds
57-
@client = Mongo::MongoShardedClient.new(seeds)
59+
@client = MongoShardedClient.new(seeds)
5860
assert @client.connected?
5961
routers = @sc.servers(:routers)
6062
while routers.size > 0 do

test/unit/read_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ReadTest < Test::Unit::TestCase
55
context "Read mode on standard connection: " do
66
setup do
77
@read_preference = :secondary
8-
@client = Mongo::MongoClient.new('localhost', 27017, :read => @read_preference, :connect => false)
8+
@client = MongoClient.new('localhost', 27017, :read => @read_preference, :connect => false)
99
end
1010

1111
end
@@ -16,7 +16,7 @@ class ReadTest < Test::Unit::TestCase
1616
@acceptable_latency = 100
1717
@tags = {"dc" => "Tyler", "rack" => "Brock"}
1818
@bad_tags = {"wow" => "cool"}
19-
@client = Mongo::MongoReplicaSetClient.new(
19+
@client = MongoReplicaSetClient.new(
2020
['localhost:27017'],
2121
:read => @read_preference,
2222
:tag_sets => @tags,

test/unit/write_concern_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Mongo::MongoClient
1616
end
1717

1818
@client =
19-
Mongo::MongoClient.new('localhost', 27017,
19+
MongoClient.new('localhost', 27017,
2020
@write_concern.merge({:connect => false}))
2121
end
2222

0 commit comments

Comments
 (0)