lib/mongo_mapper/connection.rb in mongo_mapper-0.12.0 vs lib/mongo_mapper/connection.rb in mongo_mapper-0.13.0.beta1
- old
+ new
@@ -8,13 +8,17 @@
@@database_name = nil
@@config = nil
# @api public
def connection
- @@connection ||= Mongo::Connection.new
+ @@connection ||= Mongo::MongoClient.new
end
+ def connection?
+ !!@@connection
+ end
+
# @api public
def connection=(new_connection)
@@connection = new_connection
end
@@ -63,22 +67,27 @@
def connect(environment, options={})
raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
env = config_for_environment(environment)
- if env['options'].is_a? Hash
+ if env['options'].is_a?(Hash)
options = env['options'].symbolize_keys.merge(options)
end
+ options[:read] = options[:read].to_sym if options[:read].is_a? String
+ if env.key?('ssl')
+ options[:ssl] = env['ssl']
+ end
+
MongoMapper.connection = if env['hosts']
if env['hosts'].first.is_a?(String)
- Mongo::ReplSetConnection.new( env['hosts'], options )
+ Mongo::MongoReplicaSetClient.new( env['hosts'], options )
else
- Mongo::ReplSetConnection.new( *env['hosts'].push(options) )
+ Mongo::MongoReplicaSetClient.new( *env['hosts'].push(options) )
end
else
- Mongo::Connection.new(env['host'], env['port'], options)
+ Mongo::MongoClient.new(env['host'], env['port'], options)
end
MongoMapper.database = env['database']
MongoMapper.database.authenticate(env['username'], env['password']) if env['username'] && env['password']
end
@@ -88,13 +97,15 @@
self.config = config
connect(environment, options)
end
def handle_passenger_forking
+ # :nocov:
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
connection.connect if forked
end
end
+ # :nocov:
end
end
-end
\ No newline at end of file
+end