Module: Mongo::JavaImpl::Connection_::ClassMethods

Included in:
Connection
Defined in:
lib/jmongo/mongo/connection.rb

Constant Summary collapse

URI_RE =
/^mongodb:\/\/(([-.\w]+):([^@]+)@)?([-.\w]+)(:([\w]+))?(\/([-\w]+))?/
OPTS_KEYS =
%W[maxpoolsize connecttimeoutms autoconnectretry
waitqueuemultiple waitqueuetimeoutms sockettimeoutms
slaveok safe w wtimeout fsync]

Instance Method Summary collapse

Instance Method Details

#_from_uri(uri, opts = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jmongo/mongo/connection.rb', line 25

def _from_uri uri, opts={}
  optarr = []
  unless uri =~ URI_RE
    raise MongoArgumentError, "MongoDB URI incorrect"
  end
  pieces = uri.split("//")
  extra = pieces.last.count('/') == 0 ? "/" : ""
  opts.each do|k,v|
    if OPTS_KEYS.include?(k.to_s) && !v.nil?
      (optarr << "#{k}=#{v}")
    end
  end
  unless optarr.empty?
    uri << "#{extra}?" << optarr.join("&")
  end
  opts[:new_from_uri] = Java::ComMongodb::MongoURI.new(uri)
  new("",0,opts)
end