class Gem::Uri
Uri
类处理 rubygems 源 URI。
属性
parsed_uri[R]
为克隆实例添加受保护的读取器,以访问原始对象的已解析 URI
公共类方法
new(source_uri) 点击切换源代码
# File rubygems/uri.rb, line 46 def initialize(source_uri) @parsed_uri = parse(source_uri) end
parse(uri) 点击切换源代码
解析 URI,如果 URI 无效,则返回原始 URI
# File rubygems/uri.rb, line 40 def self.parse(uri) parse!(uri) rescue Gem::URI::InvalidURIError uri end
parse!(uri) 点击切换源代码
解析 URI,如果 URI 无效,则抛出异常
# File 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::RFC2396_PARSER.escape(uri)) end end
redact(uri) 点击切换源代码
解析并编辑 URI
# File rubygems/uri.rb, line 11 def self.redact(uri) new(uri).redacted end
公共实例方法
method_missing(method_name, *args, &blk) 点击切换源代码
调用父类方法
# File 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
redact_credentials_from(text) 点击切换源代码
# File 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
redacted() 点击切换源代码
# File 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
respond_to_missing?(method_name, include_private = false) 点击切换源代码
调用父类方法
# File rubygems/uri.rb, line 80 def respond_to_missing?(method_name, include_private = false) @parsed_uri.respond_to?(method_name, include_private) || super end
to_s() 点击切换源代码
# File rubygems/uri.rb, line 62 def to_s @parsed_uri.to_s end
私有实例方法
initialize_copy(original) 点击切换源代码
# File rubygems/uri.rb, line 123 def initialize_copy(original) @parsed_uri = original.parsed_uri.clone end
oauth_basic?() 点击切换源代码
# File rubygems/uri.rb, line 115 def oauth_basic? password == "x-oauth-basic" end
parse(uri) 点击切换源代码
# File rubygems/uri.rb, line 95 def parse(uri) self.class.parse(uri) end
parse!(uri) 点击切换源代码
# File rubygems/uri.rb, line 91 def parse!(uri) self.class.parse!(uri) end
password?() 点击切换源代码
# File rubygems/uri.rb, line 111 def password? !!password end
token?() 点击切换源代码
# File rubygems/uri.rb, line 119 def token? !user.nil? && password.nil? end
valid_uri?() 点击切换源代码
# File rubygems/uri.rb, line 107 def valid_uri? !@parsed_uri.is_a?(String) end
with_redacted_password() 点击切换源代码
# File rubygems/uri.rb, line 103 def with_redacted_password clone.tap {|uri| uri.password = "REDACTED" } end
with_redacted_user() 点击切换源代码
# File rubygems/uri.rb, line 99 def with_redacted_user clone.tap {|uri| uri.user = "REDACTED" } end