Class: Proxy
- Inherits:
-
Object
- Object
- Proxy
- Defined in:
- lib/sty/proxy.rb
Instance Method Summary collapse
- #action(px) ⇒ Object
- #config ⇒ Object
- #output(strings) ⇒ Object
- #proxy_vars ⇒ Object
- #set(px) ⇒ Object
- #unset ⇒ Object
Instance Method Details
#action(px) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sty/proxy.rb', line 40 def action(px) case when px.nil? STDERR.puts "Current proxy vars:" proxy_vars.each do |k,v| STDERR.puts "#{k}=#{v}" end when px =~ /off/i STDERR.puts "Proxy vars unset" output(unset) else output(unset + set(px)) end end |
#config ⇒ Object
5 6 7 |
# File 'lib/sty/proxy.rb', line 5 def config @config = @config || yaml('proxy') end |
#output(strings) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sty/proxy.rb', line 33 def output(strings) puts "#EVAL#" strings.each do |s| puts "#{s};" end end |
#proxy_vars ⇒ Object
9 10 11 |
# File 'lib/sty/proxy.rb', line 9 def proxy_vars ENV.select { |e| e =~ /(https?|no)_proxy/i } end |
#set(px) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sty/proxy.rb', line 19 def set(px) proxy = config[px] unless proxy STDERR.puts red("ERROR! Proxy #{px} was not found in the config file.") exit 1 end STDERR.puts "Proxy is set to #{proxy['proxy']}" ["export http_proxy=#{proxy['proxy']}", "export https_proxy=#{proxy['proxy']}", "export no_proxy=#{proxy['no-proxy']}"] end |
#unset ⇒ Object
13 14 15 16 17 |
# File 'lib/sty/proxy.rb', line 13 def unset proxy_vars.keys.map do |e| "unset #{e}" end end |