Class: Chromedriver::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/chromedriver2/helper.rb,
lib/chromedriver2/helper/version.rb,
lib/chromedriver2/helper/google_code_parser.rb

Defined Under Namespace

Classes: GoogleCodeParser

Constant Summary collapse

VERSION =
"0.0.8"

Instance Method Summary collapse

Instance Method Details

#binary_pathObject



35
36
37
# File 'lib/chromedriver2/helper.rb', line 35

def binary_path
  File.join platform_install_dir, "chromedriver"
end

#download(hit_network = false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chromedriver2/helper.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/chromedriver2/helper.rb', line 31

def download_url
  GoogleCodeParser.new(platform).newest_download
end

#install_dirObject



45
46
47
48
49
# File 'lib/chromedriver2/helper.rb', line 45

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

#platformObject



51
52
53
54
55
56
57
58
59
# File 'lib/chromedriver2/helper.rb', line 51

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

#platform_install_dirObject



39
40
41
42
43
# File 'lib/chromedriver2/helper.rb', line 39

def platform_install_dir
  dir = File.join install_dir, platform.gsub('?','')
  FileUtils.mkdir_p dir
  dir
end

#run(*args) ⇒ Object



9
10
11
12
# File 'lib/chromedriver2/helper.rb', line 9

def run *args
  download
  exec binary_path, *args
end

#updateObject



27
28
29
# File 'lib/chromedriver2/helper.rb', line 27

def update
  download true
end