more readability changes to uri_parser regex
This commit is contained in:
parent
1d22c75811
commit
899241eefe
|
@ -21,15 +21,15 @@ module Mongo
|
||||||
|
|
||||||
DEFAULT_PORT = 27017
|
DEFAULT_PORT = 27017
|
||||||
|
|
||||||
USER_REGEX = /([-.\w:]+)/
|
USER_REGEX = /(?<username>[-.\w:]+)/
|
||||||
PASS_REGEX = /([^@,]+)/
|
PASS_REGEX = /(?<password>[^@,]+)/
|
||||||
AUTH_REGEX = /(#{USER_REGEX}:#{PASS_REGEX}@)?/
|
AUTH_REGEX = /(?<auth>#{USER_REGEX}:#{PASS_REGEX}@)?/
|
||||||
|
|
||||||
HOST_REGEX = /(?:[-.\w]+)/
|
HOST_REGEX = /(?<host>[-.\w]+)/
|
||||||
PORT_REGEX = /(?::(?:[\d]+))/
|
PORT_REGEX = /(?::(?<port>\d+))?/
|
||||||
NODE_REGEX = /((?:#{HOST_REGEX}#{PORT_REGEX}?,?)+)/
|
NODE_REGEX = /((?<nodes>#{HOST_REGEX}#{PORT_REGEX},?)+)/
|
||||||
|
|
||||||
PATH_REGEX = /(\/([-\w]+))?/
|
PATH_REGEX = /(?:\/(?<path>[-\w]+))?/
|
||||||
|
|
||||||
MONGODB_URI_MATCHER = /#{AUTH_REGEX}#{NODE_REGEX}#{PATH_REGEX}/
|
MONGODB_URI_MATCHER = /#{AUTH_REGEX}#{NODE_REGEX}#{PATH_REGEX}/
|
||||||
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]"
|
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]"
|
||||||
|
@ -130,10 +130,10 @@ module Mongo
|
||||||
raise MongoArgumentError, "MongoDB URI must match this spec: #{MONGODB_URI_SPEC}"
|
raise MongoArgumentError, "MongoDB URI must match this spec: #{MONGODB_URI_SPEC}"
|
||||||
end
|
end
|
||||||
|
|
||||||
uname = matches[2]
|
uname = matches['username']
|
||||||
pwd = matches[3]
|
pwd = matches['password']
|
||||||
hosturis = matches[4].split(',')
|
hosturis = matches['nodes'].split(',')
|
||||||
db = matches[6]
|
db = matches['path']
|
||||||
|
|
||||||
hosturis.each do |hosturi|
|
hosturis.each do |hosturi|
|
||||||
# If port is present, use it, otherwise use default port
|
# If port is present, use it, otherwise use default port
|
||||||
|
|
Loading…
Reference in New Issue