1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/uri] Simplify construction of URI instances using parser interface.

https://github.com/ruby/uri/commit/c145017dd7
This commit is contained in:
Samuel Williams 2019-12-28 11:36:41 +13:00 committed by Hiroshi SHIBATA
parent e460c2d033
commit 844ff7ea45
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
3 changed files with 16 additions and 25 deletions

View file

@ -145,6 +145,20 @@ module URI
@@schemes
end
#
# Construct a URI instance, using the scheme to detect the appropriate class
# from +URI.scheme_list+.
#
def self.for(scheme, *arguments, default: Generic)
if scheme
uri_class = @@schemes[scheme.upcase] || default
else
uri_class = default
end
return uri_class.new(scheme, *arguments)
end
#
# Base class for all URI exceptions.
#

View file

@ -208,21 +208,9 @@ module URI
# #=> #<URI::LDAP ldap://ldap.example.com/dc=example?user=john>
#
def parse(uri)
scheme, userinfo, host, port,
registry, path, opaque, query, fragment = self.split(uri)
if scheme && URI.scheme_list.include?(scheme.upcase)
URI.scheme_list[scheme.upcase].new(scheme, userinfo, host, port,
registry, path, opaque, query,
fragment, self)
else
Generic.new(scheme, userinfo, host, port,
registry, path, opaque, query,
fragment, self)
end
URI.for(*self.split(uri), self)
end
#
# == Args
#

View file

@ -69,18 +69,7 @@ module URI
end
def parse(uri) # :nodoc:
scheme, userinfo, host, port,
registry, path, opaque, query, fragment = self.split(uri)
scheme_list = URI.scheme_list
if scheme && scheme_list.include?(uc = scheme.upcase)
scheme_list[uc].new(scheme, userinfo, host, port,
registry, path, opaque, query,
fragment, self)
else
Generic.new(scheme, userinfo, host, port,
registry, path, opaque, query,
fragment, self)
end
URI.for(*self.split(uri), self)
end