lib/mongo_mapper/connection.rb in mongo_mapper-0.9.1 vs lib/mongo_mapper/connection.rb in mongo_mapper-0.9.2

- old
+ new

@@ -42,11 +42,11 @@ @@config end # @api private def config_for_environment(environment) - env = config[environment] + env = config[environment] || {} return env if env['uri'].blank? uri = URI.parse(env['uri']) raise InvalidScheme.new('must be mongodb') unless uri.scheme == 'mongodb' { @@ -59,10 +59,16 @@ end def connect(environment, options={}) raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank? env = config_for_environment(environment) - MongoMapper.connection = Mongo::Connection.new(env['host'], env['port'], options) + + MongoMapper.connection = if env['hosts'] + Mongo::ReplSetConnection.new( *env['hosts'].push(options) ) + else + Mongo::Connection.new(env['host'], env['port'], options) + end + MongoMapper.database = env['database'] MongoMapper.database.authenticate(env['username'], env['password']) if env['username'] && env['password'] end def setup(config, environment, options={}) \ No newline at end of file