Module: Phantomjs
- Defined in:
- lib/phantomjs.rb,
lib/phantomjs/version.rb,
lib/phantomjs/platform.rb
Defined Under Namespace
Classes: Platform
Constant Summary collapse
- UnknownPlatform =
Class.new StandardError
- VERSION =
'2.0.0.2'
Class Attribute Summary collapse
-
.proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
.proxy_port ⇒ Object
Returns the value of attribute proxy_port.
Class Method Summary collapse
- .available_platforms ⇒ Object
- .base_dir ⇒ Object
- .base_dir=(dir) ⇒ Object
-
.implode! ⇒ Object
Removes the local phantomjs copy.
- .path ⇒ Object
- .platform ⇒ Object
-
.reset! ⇒ Object
Clears cached state.
-
.run(*args, &block) ⇒ Object
Run phantomjs with the given arguments, and either return the stdout or yield each line to the passed block.
- .version ⇒ Object
Class Attribute Details
.proxy_host ⇒ Object
Returns the value of attribute proxy_host.
8 9 10 |
# File 'lib/phantomjs.rb', line 8 def proxy_host @proxy_host end |
.proxy_port ⇒ Object
Returns the value of attribute proxy_port.
8 9 10 |
# File 'lib/phantomjs.rb', line 8 def proxy_port @proxy_port end |
Class Method Details
.available_platforms ⇒ Object
10 11 12 |
# File 'lib/phantomjs.rb', line 10 def available_platforms @available_platforms ||= [] end |
.base_dir ⇒ Object
14 15 16 |
# File 'lib/phantomjs.rb', line 14 def base_dir @base_dir ||= File.join(File.('~'), '.phantomjs', version) end |
.base_dir=(dir) ⇒ Object
18 19 20 |
# File 'lib/phantomjs.rb', line 18 def base_dir=(dir) @base_dir = dir end |
.implode! ⇒ Object
Removes the local phantomjs copy
40 41 42 |
# File 'lib/phantomjs.rb', line 40 def implode! FileUtils.rm_rf File.join(File.('~'), '.phantomjs') end |
.path ⇒ Object
26 27 28 |
# File 'lib/phantomjs.rb', line 26 def path @path ||= platform.phantomjs_path end |
.platform ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/phantomjs.rb', line 30 def platform if platform = available_platforms.find { |p| p.useable? } platform.ensure_installed! platform else raise UnknownPlatform, "Could not find an appropriate PhantomJS library for your platform (#{RUBY_PLATFORM} :( Please install manually." end end |
.reset! ⇒ Object
Clears cached state. Primarily useful for testing.
45 46 47 |
# File 'lib/phantomjs.rb', line 45 def reset! @base_dir = @path = nil end |
.run(*args, &block) ⇒ Object
Run phantomjs with the given arguments, and either return the stdout or yield each line to the passed block.
51 52 53 54 55 |
# File 'lib/phantomjs.rb', line 51 def run(*args, &block) IO.popen([path, *args]) do |io| block ? io.each(&block) : io.read end end |