Class: Phantomjs
- Inherits:
-
Object
- Object
- Phantomjs
- Defined in:
- lib/indexable/phantomjs.rb
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(script, *args) ⇒ Phantomjs
constructor
A new instance of Phantomjs.
- #run ⇒ Object
Constructor Details
#initialize(script, *args) ⇒ Phantomjs
Returns a new instance of Phantomjs.
6 7 8 9 10 |
# File 'lib/indexable/phantomjs.rb', line 6 def initialize(script, *args) @script = script @args = args @timeout = 20 end |
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
4 5 6 |
# File 'lib/indexable/phantomjs.rb', line 4 def timeout @timeout end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/indexable/phantomjs.rb', line 12 def run pipe = nil begin Timeout.timeout(@timeout) do pipe = IO.popen(["phantomjs", @script] + @args) Process.wait pipe.pid return pipe.read end rescue Timeout::Error Process.kill 9, pipe.pid Process.wait pipe.pid return "Couldn't render page... orz." end end |