Permalink
Browse files

Cleaning up module includes and namespace refs

  • Loading branch information...
1 parent 5be9f6a commit 81f3314a873f18ffcfbabb95b5f393fbd0408aec @estolfo estolfo committed Nov 26, 2012
View
@@ -47,7 +47,9 @@ Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](https://githu
require 'rubygems'
require 'mongo'
-@client = Mongo::MongoClient.new('localhost', 27017)
+include Mongo
+
+@client = MongoClient.new('localhost', 27017)
@db = @client['sample-db']
@coll = @db['test']
@@ -207,7 +209,8 @@ You can tell the Ruby Mongo driver how to create primary keys by passing in
the :pk option to the MongoClient#db method.
```ruby
-db = Mongo::MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
+include Mongo
+db = MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
```
A primary key factory object must respond to :create_pk, which should
View
@@ -9,7 +9,7 @@
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
-client = Mongo::MongoClient.new(host, port)
+client = MongoClient.new(host, port)
db = client.db('ruby-mongo-examples')
coll = db.create_collection('test')
View
@@ -1,10 +1,12 @@
# This code assumes a running replica set with at least one node at localhost:27017.
require 'mongo'
+include Mongo
+
cons = []
10.times do
- cons << Mongo::MongoReplicaSetClient(['localhost:27017'], :read => :secondary)
+ cons << MongoReplicaSetClient(['localhost:27017'], :read => :secondary)
end
ports = cons.map do |con|
@@ -1,7 +1,9 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'mongo')
require 'logger'
-$con = Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary, :refresh_mode => :sync, :refresh_interval => 30)
+include Mongo
+
+$con = MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary, :refresh_mode => :sync, :refresh_interval => 30)
$db = $con['foo']
class Load < Sinatra::Base
@@ -1,6 +1,8 @@
-require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mongo')
+require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'mongo')
-$client = Mongo::MongoClient.new('localhost', 27017)
+include Mongo
+
+$client = MongoClient.new('localhost', 27017)
$db = $client['foo']
class Load < Sinatra::Base
@@ -95,16 +95,16 @@ class MongoClient
# @option opts [Boolean] :ssl (false) If true, create the connection to the server using SSL.
#
# @example localhost, 27017 (or <code>ENV["MONGODB_URI"]</code> if available)
- # Mongo::MongoClient.new
+ # MongoClient.new
#
# @example localhost, 27017
- # Mongo::MongoClient.new("localhost")
+ # MongoClient.new("localhost")
#
# @example localhost, 3000, max 5 self.connections, with max 5 seconds of wait time.
- # Mongo::MongoClient.new("localhost", 3000, :pool_size => 5, :timeout => 5)
+ # MongoClient.new("localhost", 3000, :pool_size => 5, :timeout => 5)
#
# @example localhost, 3000, where this node may be a slave
- # Mongo::MongoClient.new("localhost", 3000, :slave_ok => true)
+ # MongoClient.new("localhost", 3000, :slave_ok => true)
#
# @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
#
@@ -94,13 +94,13 @@ class MongoReplicaSetClient < MongoClient
# The purpose of seed nodes is to permit the driver to find at least one replica set member even if a member is down.
#
# @example Connect to a replica set and provide two seed nodes.
- # Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'])
+ # MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'])
#
# @example Connect to a replica set providing two seed nodes and ensuring a connection to the replica set named 'prod':
- # Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :name => 'prod')
+ # MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :name => 'prod')
#
# @example Connect to a replica set providing two seed nodes and allowing reads from a secondary node:
- # Mongo::MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary)
+ # MongoReplicaSetClient.new(['localhost:30000', 'localhost:30001'], :read => :secondary)
#
# @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
#
@@ -58,7 +58,7 @@ class MongoShardedClient < MongoReplicaSetClient
# The purpose of seed nodes is to permit the driver to find at least one sharded cluster member even if a member is down.
#
# @example Connect to a sharded cluster and provide two seed nodes.
- # Mongo::MongoShardedClient.new(['localhost:30000', 'localhost:30001'])
+ # MongoShardedClient.new(['localhost:30000', 'localhost:30001'])
#
# @raise [MongoArgumentError] This is raised for usage errors.
#
@@ -179,7 +179,7 @@ def port
nodes[0][1].to_i
end
- # Options that can be passed to Mongo::MongoClient.new or Mongo::MongoReplicaSetClient.new
+ # Options that can be passed to MongoClient.new or MongoReplicaSetClient.new
# @return [Hash]
def connection_options
opts = {}
@@ -7,7 +7,7 @@ class Features14Test < Test::Unit::TestCase
context "MongoDB 1.4" do
setup do
- @client = Mongo::MongoClient.new
+ @client = MongoClient.new
@db = @client['mongo-ruby-test']
@col = @db['new-features']
end
@@ -7,7 +7,7 @@ class AuthenticationTest < Test::Unit::TestCase
include Mongo
def setup
- @client = Mongo::MongoClient.new
+ @client = MongoClient.new
@db1 = @client.db('mongo-ruby-test-auth1')
@db2 = @client.db('mongo-ruby-test-auth2')
@admin = @client.db('admin')
@@ -6,7 +6,7 @@ class AutoreconnectTest < Test::Unit::TestCase
include Mongo
def setup
- @client = Mongo::MongoClient.new
+ @client = MongoClient.new
@db = @client.db('mongo-ruby-test')
@db.drop_collection("test-connect")
@coll = @db.collection("test-connect")
@@ -18,7 +18,7 @@ def teardown
def test_connection_failure
assert_raise Mongo::ConnectionFailure do
- Mongo::MongoClient.new('localhost', 27347)
+ MongoClient.new('localhost', 27347)
end
end
@@ -2,8 +2,6 @@
class DBConnectionTest < Test::Unit::TestCase
- include Mongo
-
def test_no_exceptions
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
@@ -12,31 +12,31 @@ def self.shutdown
end
def test_connect
- client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
assert client.connected?
assert_equal @rs.primary_name, client.primary.join(':')
assert_equal @rs.secondary_names.sort, client.secondaries.collect{|s| s.join(':')}.sort
assert_equal @rs.arbiter_names.sort, client.arbiters.collect{|s| s.join(':')}.sort
client.close
silently do
- client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds_old, :name => @rs.repl_set_name)
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds_old, :name => @rs.repl_set_name)
end
assert client.connected?
client.close
end
def test_safe_option
- client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
assert client.connected?
assert client.write_concern[:w] > 0
client.close
- client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 0)
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 0)
assert client.connected?
assert client.write_concern[:w] < 1
client.close
- client = Mongo::MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 2)
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 2)
assert client.connected?
assert client.write_concern[:w] > 0
client.close
@@ -25,7 +25,7 @@ def test_cursors_get_closed
def setup_client(read=:primary)
# Setup ReplicaSet Connection
- @client = Mongo::MongoReplicaSetClient.new(
+ @client = MongoReplicaSetClient.new(
@rs.repl_set_seeds,
:read => read
)
@@ -1,6 +1,8 @@
require 'test_helper'
+include Mongo
class BasicTest < Test::Unit::TestCase
+
def setup
ensure_cluster(:sc)
end
@@ -13,7 +15,7 @@ def self.shutdown
# TODO member.primary? ==> true
def test_connect
seeds = @sc.mongos_seeds
- @client = Mongo::MongoShardedClient.new(seeds)
+ @client = MongoShardedClient.new(seeds)
assert @client.connected?
assert_equal(seeds.size, @client.seeds.size)
probe(seeds.size)
@@ -22,7 +24,7 @@ def test_connect
def test_hard_refresh
seeds = @sc.mongos_seeds
- @client = Mongo::MongoShardedClient.new(seeds)
+ @client = MongoShardedClient.new(seeds)
assert @client.connected?
@client.hard_refresh!
assert @client.connected?
@@ -31,7 +33,7 @@ def test_hard_refresh
def test_reconnect
seeds = @sc.mongos_seeds
- @client = Mongo::MongoShardedClient.new(seeds)
+ @client = MongoShardedClient.new(seeds)
assert @client.connected?
router = @sc.servers(:routers).first
router.stop
@@ -42,7 +44,7 @@ def test_reconnect
def test_all_down
seeds = @sc.mongos_seeds
- @client = Mongo::MongoShardedClient.new(seeds)
+ @client = MongoShardedClient.new(seeds)
assert @client.connected?
@sc.servers(:routers).each{|router| router.stop}
assert_raises Mongo::ConnectionFailure do
@@ -54,7 +56,7 @@ def test_all_down
def test_cycle
seeds = @sc.mongos_seeds
- @client = Mongo::MongoShardedClient.new(seeds)
+ @client = MongoShardedClient.new(seeds)
assert @client.connected?
routers = @sc.servers(:routers)
while routers.size > 0 do
View
@@ -5,7 +5,7 @@ class ReadTest < Test::Unit::TestCase
context "Read mode on standard connection: " do
setup do
@read_preference = :secondary
- @client = Mongo::MongoClient.new('localhost', 27017, :read => @read_preference, :connect => false)
+ @client = MongoClient.new('localhost', 27017, :read => @read_preference, :connect => false)
end
end
@@ -16,7 +16,7 @@ class ReadTest < Test::Unit::TestCase
@acceptable_latency = 100
@tags = {"dc" => "Tyler", "rack" => "Brock"}
@bad_tags = {"wow" => "cool"}
- @client = Mongo::MongoReplicaSetClient.new(
+ @client = MongoReplicaSetClient.new(
['localhost:27017'],
:read => @read_preference,
:tag_sets => @tags,
@@ -16,7 +16,7 @@ class Mongo::MongoClient
end
@client =
- Mongo::MongoClient.new('localhost', 27017,
+ MongoClient.new('localhost', 27017,
@write_concern.merge({:connect => false}))
end

0 comments on commit 81f3314

Please sign in to comment.