Class: Chromedriver::Helper
- Inherits:
-
Object
- Object
- Chromedriver::Helper
show all
- Defined in:
- lib/chromedriver/helper.rb,
lib/chromedriver/helper/version.rb,
lib/chromedriver/helper/google_code_parser.rb
Defined Under Namespace
Classes: GoogleCodeParser
Constant Summary
collapse
- VERSION =
"1.1.0"
Instance Method Summary
collapse
Instance Method Details
#base_install_dir ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/chromedriver/helper.rb', line 92
def base_install_dir
@base_install_dir ||= begin
dir = File.expand_path File.join(ENV['HOME'], ".chromedriver-helper")
FileUtils.mkdir_p dir
dir
end
end
|
#binary_path ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/chromedriver/helper.rb', line 72
def binary_path
if platform == "win"
File.join platform_install_dir, "chromedriver.exe"
else
File.join platform_install_dir, "chromedriver"
end
end
|
#current_version ⇒ Object
50
51
52
53
54
|
# File 'lib/chromedriver/helper.rb', line 50
def current_version
@current_version ||= if File.exist?(version_path)
File.read(version_path).strip
end
end
|
#download(hit_network = false) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/chromedriver/helper.rb', line 19
def download(hit_network = false)
return if File.exist?(binary_path) && !hit_network
raise "Version not found for #{download_version}" unless download_url
filename = File.basename download_url
Dir.chdir platform_install_dir do
FileUtils.rm_f filename
File.open(filename, "wb") do |saved_file|
URI.parse(download_url).open("rb") do |read_file|
saved_file.write(read_file.read)
end
end
raise "Could not download #{download_url}" unless File.exists? filename
Archive::Zip.(filename, '.', :overwrite => :all)
end
raise "Could not unzip #{filename} to get #{binary_path}" unless File.exists? binary_path
FileUtils.chmod "ugo+rx", binary_path
File.open(version_path, 'w') { |file| file.write(download_version) }
end
|
#download_url ⇒ Object
60
61
62
|
# File 'lib/chromedriver/helper.rb', line 60
def download_url
@download_url ||= google_code_parser.version_download_url(download_version)
end
|
#download_version ⇒ Object
56
57
58
|
# File 'lib/chromedriver/helper.rb', line 56
def download_version
@download_version ||= current_version || google_code_parser.newest_download_version.to_s
end
|
#google_code_parser ⇒ Object
64
65
66
|
# File 'lib/chromedriver/helper.rb', line 64
def google_code_parser
@google_code_parser ||= GoogleCodeParser.new(platform)
end
|
100
101
102
103
104
105
106
107
108
|
# File 'lib/chromedriver/helper.rb', line 100
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
|
80
81
82
83
84
|
# File 'lib/chromedriver/helper.rb', line 80
def platform_install_dir
dir = File.join version_install_dir, platform
FileUtils.mkdir_p dir
dir
end
|
#run(*args) ⇒ Object
14
15
16
17
|
# File 'lib/chromedriver/helper.rb', line 14
def run(*args)
download
exec binary_path, *args
end
|
#update(version = nil) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/chromedriver/helper.rb', line 41
def update(version = nil)
if version
@download_version = version
end
hit_network = (current_version != download_version) ? true : false
download(hit_network)
end
|
#version_install_dir ⇒ Object
86
87
88
89
90
|
# File 'lib/chromedriver/helper.rb', line 86
def version_install_dir
dir = File.expand_path File.join(base_install_dir, download_version)
FileUtils.mkdir_p dir
dir
end
|
#version_path ⇒ Object
68
69
70
|
# File 'lib/chromedriver/helper.rb', line 68
def version_path
@version_path ||= File.join(base_install_dir, ".chromedriver-version")
end
|