The Uri
handles rubygems source URIs.
# File ruby-3.1.2/lib/rubygems/uri.rb, line 34 def method_missing(method_name, *args, &blk) if @parsed_uri.respond_to?(method_name) @parsed_uri.send(method_name, *args, &blk) else super end end
# File ruby-3.1.2/lib/rubygems/uri.rb, line 28 def redact_credentials_from(text) return text unless valid_uri? && password? text.sub(password, 'REDACTED') end
# File ruby-3.1.2/lib/rubygems/uri.rb, line 12 def redacted return self unless valid_uri? if token? || oauth_basic? with_redacted_user elsif password? with_redacted_password else self end end
# File ruby-3.1.2/lib/rubygems/uri.rb, line 108 def initialize_copy(original) @parsed_uri = original.parsed_uri.clone end
# File ruby-3.1.2/lib/rubygems/uri.rb, line 100 def oauth_basic? password == 'x-oauth-basic' end
Parses the uri, returning the original uri if it's invalid
# File ruby-3.1.2/lib/rubygems/uri.rb, line 76 def parse(uri) return uri unless uri.is_a?(String) parse!(uri) rescue URI::InvalidURIError uri end
Parses the uri, raising if it's invalid
# File ruby-3.1.2/lib/rubygems/uri.rb, line 56 def parse!(uri) require "uri" raise URI::InvalidURIError unless uri # Always escape URI's to deal with potential spaces and such # It should also be considered that source_uri may already be # a valid URI with escaped characters. e.g. "{DESede}" is encoded # as "%7BDESede%7D". If this is escaped again the percentage # symbols will be escaped. begin URI.parse(uri) rescue URI::InvalidURIError URI.parse(URI::DEFAULT_PARSER.escape(uri)) end end
# File ruby-3.1.2/lib/rubygems/uri.rb, line 96 def password? !!password end
# File ruby-3.1.2/lib/rubygems/uri.rb, line 104 def token? !user.nil? && password.nil? end
# File ruby-3.1.2/lib/rubygems/uri.rb, line 92 def valid_uri? !@parsed_uri.is_a?(String) end