Class: Chromedriver::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/chromedriver/installer.rb,
lib/chromedriver/installer/version.rb,
lib/chromedriver/installer/google_code_parser.rb

Defined Under Namespace

Classes: GoogleCodeParser

Constant Summary collapse

VERSION =
"0.0.6"

Instance Method Summary collapse

Instance Method Details

#binary_pathObject



35
36
37
38
39
40
41
# File 'lib/chromedriver/installer.rb', line 35

def binary_path
  if platform == "win"
    File.join platform_install_dir, "chromedriver.exe"
  else
    File.join platform_install_dir, "chromedriver"
  end
end

#download(hit_network = false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chromedriver/installer.rb', line 14

def download hit_network=false
  return if File.exists?(binary_path) && ! hit_network
  url = download_url
  filename = File.basename url
  Dir.chdir platform_install_dir do
    system "rm #{filename}"
    system("wget -c -O #{filename} #{url}") || system("curl -C - -o #{filename} #{url}")
    raise "Could not download #{url}" unless File.exists? filename
    system "unzip -o #{filename}"
  end
  raise "Could not unzip #{filename} to get #{binary_path}" unless File.exists? binary_path
end

#download_urlObject



31
32
33
# File 'lib/chromedriver/installer.rb', line 31

def download_url
  GoogleCodeParser.new(platform).newest_download
end

#install_dirObject



49
50
51
52
53
# File 'lib/chromedriver/installer.rb', line 49

def install_dir
  dir = File.expand_path File.join(ENV['HOME'], ".chromedriver-installer")
  FileUtils.mkdir_p dir
  dir
end

#platformObject



55
56
57
58
59
60
61
62
63
# File 'lib/chromedriver/installer.rb', line 55

def platform
  cfg = RbConfig::CONFIG
  case cfg['host_os']
  when /linux/ then
    cfg['host_cpu'] =~ /x86_64|amd64/ ? "linux64" : "linux32"
  when /darwin/ then "mac"
  else "win"
  end
end

#platform_install_dirObject



43
44
45
46
47
# File 'lib/chromedriver/installer.rb', line 43

def platform_install_dir
  dir = File.join install_dir, platform
  FileUtils.mkdir_p dir
  dir
end

#run(*args) ⇒ Object



9
10
11
12
# File 'lib/chromedriver/installer.rb', line 9

def run *args
  download
  exec binary_path, *args
end

#updateObject



27
28
29
# File 'lib/chromedriver/installer.rb', line 27

def update
  download true
end