Class: Phrender::PhantomJSSession

Inherits:
Object
  • Object
show all
Defined in:
lib/phrender/phantom_js_session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, timeout) ⇒ PhantomJSSession

Returns a new instance of PhantomJSSession.



9
10
11
12
13
14
# File 'lib/phrender/phantom_js_session.rb', line 9

def initialize(cmd, timeout)
  @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(cmd)
  @start_time = Time.now
  @rendered = false
  @timeout = timeout
end

Instance Attribute Details

#pageObject

Returns the value of attribute page.



7
8
9
# File 'lib/phrender/phantom_js_session.rb', line 7

def page
  @page
end

#renderedObject

Returns the value of attribute rendered.



6
7
8
# File 'lib/phrender/phantom_js_session.rb', line 6

def rendered
  @rendered
end

#stderrObject

Returns the value of attribute stderr.



4
5
6
# File 'lib/phrender/phantom_js_session.rb', line 4

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



2
3
4
# File 'lib/phrender/phantom_js_session.rb', line 2

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



3
4
5
# File 'lib/phrender/phantom_js_session.rb', line 3

def stdout
  @stdout
end

#wait_thrObject

Returns the value of attribute wait_thr.



5
6
7
# File 'lib/phrender/phantom_js_session.rb', line 5

def wait_thr
  @wait_thr
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/phrender/phantom_js_session.rb', line 16

def expired?
  (Time.now - @start_time) >= @timeout
end

#shutdownObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/phrender/phantom_js_session.rb', line 20

def shutdown
  [ @stdin, @stdout, @stderr ].each do |pipe|
    begin
      pipe.close
    rescue IOError
    end
  end
  begin
    Process.kill("TERM", @wait_thr.pid)
  rescue Errno::ESRCH
  end
end