Class: AOJ::Env
- Inherits:
-
Object
- Object
- AOJ::Env
- Defined in:
- lib/aoj/env.rb
Instance Method Summary collapse
-
#initialize(env = ENV) ⇒ Env
constructor
A new instance of Env.
-
#parse_proxy_info ⇒ Object
parse proxy from String param str : [][user:pass@]host[:port].
- #proxy_specified? ⇒ Boolean
Constructor Details
#initialize(env = ENV) ⇒ Env
4 5 6 |
# File 'lib/aoj/env.rb', line 4 def initialize(env = ENV) @env = env end |
Instance Method Details
#parse_proxy_info ⇒ Object
parse proxy from String param str : [][user:pass@]host[:port]
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/aoj/env.rb', line 10 def parse_proxy_info raw = @env["HTTP_PROXY"] || @env["http_proxy"] return {} unless raw main_str = raw .strip .sub(/^http:\/\//, "") .sub(/\/+$/, "") auth_str = main_str.match(/(.*)@/).to_a[1].to_s host_str = main_str.sub(/^.*@/, "") { host: host_str.sub(/:.*$/, ""), port: host_str.match(/:(.*)/).to_a[1].try(:to_i), # int or nil user: auth_str.sub(/:.*$/, ""), pass: auth_str.sub(/^.*:/, "") }.select { |_, value| value.present? } end |
#proxy_specified? ⇒ Boolean
29 30 31 |
# File 'lib/aoj/env.rb', line 29 def proxy_specified? parse_proxy_info != {} end |