Class: Phantomjs

Inherits:
Object
  • Object
show all
Defined in:
lib/indexable/phantomjs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#timeoutObject

Returns the value of attribute timeout.



4
5
6
# File 'lib/indexable/phantomjs.rb', line 4

def timeout
  @timeout
end

Instance Method Details

#runObject



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