Module: Phantomjs
- Defined in:
- lib/phantomjs.rb,
lib/phantomjs/version.rb,
lib/phantomjs/platform.rb
Defined Under Namespace
Classes: Platform, UnknownPlatform
Constant Summary collapse
- VERSION =
"1.9.2.1"
Class Method Summary collapse
- .available_platforms ⇒ Object
- .base_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 Method Details
.available_platforms ⇒ Object
8 9 10 |
# File 'lib/phantomjs.rb', line 8 def available_platforms @available_platforms ||= [] end |
.base_dir ⇒ Object
12 13 14 |
# File 'lib/phantomjs.rb', line 12 def base_dir @base_dir ||= File.join(File.('~'), '.phantomjs', version) end |
.implode! ⇒ Object
Removes the local phantomjs copy
34 35 36 |
# File 'lib/phantomjs.rb', line 34 def implode! FileUtils.rm_rf File.join(File.('~'), '.phantomjs') end |
.path ⇒ Object
20 21 22 |
# File 'lib/phantomjs.rb', line 20 def path @path ||= platform.phantomjs_path end |
.platform ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/phantomjs.rb', line 24 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.
39 40 41 |
# File 'lib/phantomjs.rb', line 39 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.
45 46 47 48 49 |
# File 'lib/phantomjs.rb', line 45 def run(*args, &block) IO.popen([path, *args]) do |io| block ? io.each(&block) : io.read end end |