class Gem::Uri
The Uri
handles rubygems source URIs.
Attributes
Add a protected reader for the cloned instance to access the original object’s parsed uri
Public Class Methods
Source
# File lib/rubygems/uri.rb, line 46 def initialize(source_uri) @parsed_uri = parse(source_uri) end
Source
# File lib/rubygems/uri.rb, line 40 def self.parse(uri) parse!(uri) rescue Gem::URI::InvalidURIError uri end
Parses uri, returning the original uri if it’s invalid
Source
# File lib/rubygems/uri.rb, line 18 def self.parse!(uri) require_relative "vendor/uri/lib/uri" raise Gem::URI::InvalidURIError unless uri return uri unless uri.is_a?(String) # 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 Gem::URI.parse(uri) rescue Gem::URI::InvalidURIError Gem::URI.parse(Gem::URI::DEFAULT_PARSER.escape(uri)) end end
Parses uri, raising if it’s invalid
Source
# File lib/rubygems/uri.rb, line 11 def self.redact(uri) new(uri).redacted end
Parses and redacts uri
Public Instance Methods
Source
# File lib/rubygems/uri.rb, line 72 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
Calls superclass method
BasicObject#method_missing
Source
# File lib/rubygems/uri.rb, line 66 def redact_credentials_from(text) return text unless valid_uri? && password? && text.include?(to_s) text.sub(password, "REDACTED") end
Source
# File lib/rubygems/uri.rb, line 50 def redacted return self unless valid_uri? if token? || oauth_basic? with_redacted_user elsif password? with_redacted_password else self end end
Source
# File lib/rubygems/uri.rb, line 80 def respond_to_missing?(method_name, include_private = false) @parsed_uri.respond_to?(method_name, include_private) || super end
Calls superclass method
Object#respond_to_missing?
Private Instance Methods
Source
# File lib/rubygems/uri.rb, line 123 def initialize_copy(original) @parsed_uri = original.parsed_uri.clone end
Source
# File lib/rubygems/uri.rb, line 115 def oauth_basic? password == "x-oauth-basic" end
Source
# File lib/rubygems/uri.rb, line 107 def valid_uri? !@parsed_uri.is_a?(String) end
Source
# File lib/rubygems/uri.rb, line 103 def with_redacted_password clone.tap {|uri| uri.password = "REDACTED" } end
Source
# File lib/rubygems/uri.rb, line 99 def with_redacted_user clone.tap {|uri| uri.user = "REDACTED" } end