Class: Phantomjs::Helper
- Inherits:
-
Object
show all
- Defined in:
- lib/phantomjs/helper.rb,
lib/phantomjs/helper/version.rb,
lib/phantomjs/helper/bitbucket_download_parser.rb
Defined Under Namespace
Classes: BitbucketDownloadParser
Constant Summary
collapse
- BUCKET_URL =
'https://bitbucket.org/ariya/phantomjs/downloads'
- VERSION =
"1.0.0"
Instance Method Summary
collapse
Instance Method Details
#binary_path ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/phantomjs/helper.rb', line 46
def binary_path
if platform == 'windows'
File.join install_dir, 'phantomjs.exe'
else
File.join install_dir, 'phantomjs'
end
end
|
#download(hit_network = false) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/phantomjs/helper.rb', line 22
def download(hit_network=false)
return if File.exists?(binary_path) && !hit_network
url = download_url
filename = File.basename url
FileUtils.mkdir_p install_dir
Dir.chdir install_dir do
FileUtils.rm_f filename
File.open(filename, 'wb') do |saved_file|
URI.parse(url).open('rb') do |read_file|
saved_file.write(read_file.read)
end
end
raise "Could not download #{url}" unless File.exists? filename
filename
FileUtils.rm_f filename
end
raise "Could not unzip #{filename} to get #{binary_path}" unless File.exists? binary_path
FileUtils.chmod 'ugo+rx', binary_path
end
|
#remove ⇒ Object
42
43
44
|
# File 'lib/phantomjs/helper.rb', line 42
def remove
FileUtils.rm binary_path
end
|
#run(*args) ⇒ Object
13
14
15
16
|
# File 'lib/phantomjs/helper.rb', line 13
def run(*args)
download
exec binary_path, *args
end
|
#update ⇒ Object
18
19
20
|
# File 'lib/phantomjs/helper.rb', line 18
def update
download true
end
|