Class: ProxyConf::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/proxyconf/engine.rb

Direct Known Subclasses

Mac

Instance Method Summary collapse

Instance Method Details

#add(name, proxy) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/proxyconf/engine.rb', line 5

def add(name, proxy)
  validate_name name
  validate_uri proxy
  filepath = File.join(ProxyConf::HOME, ProxyConf::PROXIES_DIR, name)
  File.open(filepath, "w") do |file|
    file.puts "export http_proxy=#{proxy}"
    file.puts "export ftp_proxy=#{proxy}"
    file.puts "export https_proxy=#{proxy}"
  end
end

#info(name) ⇒ Object



22
23
24
25
26
# File 'lib/proxyconf/engine.rb', line 22

def info(name)
  if_exists(name) do |filepath|
    puts File.read(filepath)
  end
end

#listObject



28
29
30
31
32
33
# File 'lib/proxyconf/engine.rb', line 28

def list
  path = File.join(ProxyConf::HOME, ProxyConf::PROXIES_DIR, "*")
  Dir.glob(path).each do |filepath|
    puts File.basename(filepath)
  end
end

#remove(name) ⇒ Object



16
17
18
19
20
# File 'lib/proxyconf/engine.rb', line 16

def remove(name)
  if_exists(name) do |filepath|
    File.delete(filepath)
  end
end