Class: Webdrivers::Common
- Inherits:
-
Object
- Object
- Webdrivers::Common
show all
- Defined in:
- lib/webdrivers/common.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.version ⇒ Object
Returns the value of attribute version.
7
8
9
|
# File 'lib/webdrivers/common.rb', line 7
def version
@version
end
|
Class Method Details
.binary ⇒ Object
90
91
92
|
# File 'lib/webdrivers/common.rb', line 90
def binary
File.join install_dir, file_name
end
|
.desired_version ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/webdrivers/common.rb', line 32
def desired_version
if version.is_a?(Gem::Version)
version
elsif version.nil?
latest_version
else
Gem::Version.new(version.to_s)
end
end
|
.download ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/webdrivers/common.rb', line 53
def download
raise StandardError, 'Can not reach site' unless site_available?
url = downloads[desired_version]
filename = File.basename url
FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir)
Dir.chdir install_dir do
FileUtils.rm_f filename
File.open(filename, 'wb') do |file|
file.print get(url)
end
raise "Could not download #{url}" unless File.exist? filename
Webdrivers.logger.debug "Successfully downloaded #{filename}"
dcf = decompress_file(filename)
Webdrivers.logger.debug 'Decompression Complete'
if dcf
Webdrivers.logger.debug "Deleting #{filename}"
FileUtils.rm_f filename
end
if respond_to? :extract_file
Webdrivers.logger.debug "Extracting #{dcf}"
(dcf)
end
end
raise "Could not decompress #{filename} to get #{binary}" unless File.exist?(binary)
FileUtils.chmod 'ugo+rx', binary
Webdrivers.logger.debug "Completed download and processing of #{binary}"
binary
end
|
.install_dir ⇒ Object
86
87
88
|
# File 'lib/webdrivers/common.rb', line 86
def install_dir
Webdrivers.install_dir || File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
end
|
.latest_version ⇒ Object
42
43
44
45
46
|
# File 'lib/webdrivers/common.rb', line 42
def latest_version
raise StandardError, 'Can not reach site' unless site_available?
downloads.keys.max
end
|
.remove ⇒ Object
48
49
50
51
|
# File 'lib/webdrivers/common.rb', line 48
def remove
Webdrivers.logger.debug "Deleting #{binary}"
FileUtils.rm_f binary
end
|
.update ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/webdrivers/common.rb', line 9
def update
unless site_available?
return current_version.nil? ? nil : binary
end
return binary if desired_version.nil? && File.exist?(binary)
if desired_version.nil?
msg = "Unable to find the latest version of #{file_name}; try downloading manually from #{base_url} and place in #{install_dir}"
raise StandardError, msg
end
if correct_binary?
Webdrivers.logger.debug 'Expected webdriver version found'
return binary
end
remove download end
|