module Phantomjs
Constants
- UnknownPlatform
- VERSION
Attributes
proxy_host[RW]
proxy_port[RW]
Public Class Methods
available_platforms()
click to toggle source
# File lib/phantomjs.rb, line 10 def available_platforms @available_platforms ||= [] end
base_dir()
click to toggle source
# File lib/phantomjs.rb, line 14 def base_dir @base_dir ||= File.join(File.expand_path('~'), '.phantomjs', version) end
base_dir=(dir)
click to toggle source
# File lib/phantomjs.rb, line 18 def base_dir=(dir) @base_dir = dir end
implode!()
click to toggle source
Removes the local phantomjs copy
# File lib/phantomjs.rb, line 40 def implode! FileUtils.rm_rf File.join(File.expand_path('~'), '.phantomjs') end
path()
click to toggle source
# File lib/phantomjs.rb, line 26 def path @path ||= platform.phantomjs_path end
platform()
click to toggle source
# 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!()
click to toggle source
Clears cached state. Primarily useful for testing.
# File lib/phantomjs.rb, line 45 def reset! @base_dir = @path = nil end
run(*args, &block)
click to toggle source
Run phantomjs with the given arguments, and either return the stdout or yield each line to the passed block.
# File lib/phantomjs.rb, line 51 def run(*args, &block) IO.popen([path, *args]) do |io| block ? io.each(&block) : io.read end end
version()
click to toggle source
# File lib/phantomjs.rb, line 22 def version Phantomjs::VERSION.split('.')[0..-2].join('.') end