Class: Phantomjs::Platform
- Inherits:
-
Object
- Object
- Phantomjs::Platform
show all
- Defined in:
- lib/phantomjs/platform.rb
Defined Under Namespace
Classes: Linux32, Linux64, OsX
Class Method Summary
collapse
Class Method Details
.architecture ⇒ Object
8
9
10
|
# File 'lib/phantomjs/platform.rb', line 8
def architecture
RbConfig::CONFIG['host_cpu']
end
|
.ensure_installed! ⇒ Object
81
82
83
|
# File 'lib/phantomjs/platform.rb', line 81
def ensure_installed!
install! unless installed?
end
|
.host_os ⇒ Object
4
5
6
|
# File 'lib/phantomjs/platform.rb', line 4
def host_os
RbConfig::CONFIG['host_os']
end
|
.install! ⇒ Object
TODO: Clean this up, it looks like a pile of…
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
|
# File 'lib/phantomjs/platform.rb', line 39
def install!
STDERR.puts "Phantomjs does not appear to be installed in #{phantomjs_path}, installing!"
FileUtils.mkdir_p Phantomjs.base_dir
temp_dir = File.join('/tmp', 'phantomjs_install')
FileUtils.rm_rf temp_dir
FileUtils.mkdir_p temp_dir
Dir.chdir temp_dir do
unless system "curl -O #{package_url}" or system "wget #{package_url}"
raise "\n\nFailed to load phantomjs! :(\nYou need to have cURL or wget installed on your system.\nIf you have, the source of phantomjs might be unavailable: #{package_url}\n\n"
end
case package_url.split('.').last
when 'bz2'
system "bunzip2 #{File.basename(package_url)}"
system "tar xf #{File.basename(package_url).sub(/\.bz2$/, '')}"
when 'zip'
system "unzip #{File.basename(package_url)}"
else
raise "Unknown compression format for #{File.basename(package_url)}"
end
= Dir['phantomjs*'].find { |path| File.directory?(path) }
if FileUtils.mv , File.join(Phantomjs.base_dir, platform)
STDOUT.puts "\nSuccessfully installed phantomjs. Yay!"
end
if FileUtils.rm_rf temp_dir
STDOUT.puts "Removed temporarily downloaded files."
end
end
raise "Failed to install phantomjs. Sorry :(" unless File.exist?(phantomjs_path)
end
|
.installed? ⇒ Boolean
34
35
36
|
# File 'lib/phantomjs/platform.rb', line 34
def installed?
File.exist?(phantomjs_path) || system_phantomjs_installed?
end
|
.phantomjs_path ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/phantomjs/platform.rb', line 12
def phantomjs_path
if system_phantomjs_installed?
system_phantomjs_path
else
File.expand_path File.join(Phantomjs.base_dir, platform, 'bin/phantomjs')
end
end
|
.system_phantomjs_installed? ⇒ Boolean
30
31
32
|
# File 'lib/phantomjs/platform.rb', line 30
def system_phantomjs_installed?
system_phantomjs_version == Phantomjs.version
end
|
.system_phantomjs_path ⇒ Object
20
21
22
23
|
# File 'lib/phantomjs/platform.rb', line 20
def system_phantomjs_path
`which phantomjs`.delete("\n")
rescue
end
|
.system_phantomjs_version ⇒ Object
25
26
27
28
|
# File 'lib/phantomjs/platform.rb', line 25
def system_phantomjs_version
`phantomjs --version`.delete("\n") if system_phantomjs_path.length > 4.2
rescue
end
|