Method: Mongo::Connection#initialize
- Defined in:
- lib/jmongo/connection.rb
#initialize(host = nil, port = nil, opts = {}) ⇒ Connection
Returns a new instance of Connection.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jmongo/connection.rb', line 27 def initialize host = nil, port = nil, opts = {} @logger = opts.delete(:logger) @auths = opts.delete(:auths) || [] if opts.has_key?(:new_from_uri) @mongo_uri = opts[:new_from_uri] = @mongo_uri. @write_concern = .write_concern @connection = JMongo::Mongo.new(@mongo_uri) else @host = host || 'localhost' @port = port || 27017 @server_address = JMongo::ServerAddress.new @host, @port = JMongo::MongoOptions.new opts.each do |k,v| key = k.to_sym jmo_key = JMongo.(key) case jmo_key when :safe @write_concern = DB.write_concern(v) .w = @write_concern.w .wtimeout = @write_concern.wtimeout .fsync = @write_concern.fsync else jmo_val = JMongo.(key, v) .send("#{jmo_key}=", jmo_val) end end @connection = JMongo::Mongo.new(@server_address, ) end @connector = @connection.connector add = @connector.address @primary = [add.host, add.port] end |