Class: Phrender::PhantomJSSession
- Inherits:
-
Object
- Object
- Phrender::PhantomJSSession
- Defined in:
- lib/phrender/phantom_js_session.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#rendered ⇒ Object
Returns the value of attribute rendered.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
-
#wait_thr ⇒ Object
Returns the value of attribute wait_thr.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(cmd, timeout) ⇒ PhantomJSSession
constructor
A new instance of PhantomJSSession.
- #shutdown ⇒ Object
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
#page ⇒ Object
Returns the value of attribute page.
7 8 9 |
# File 'lib/phrender/phantom_js_session.rb', line 7 def page @page end |
#rendered ⇒ Object
Returns the value of attribute rendered.
6 7 8 |
# File 'lib/phrender/phantom_js_session.rb', line 6 def rendered @rendered end |
#stderr ⇒ Object
Returns the value of attribute stderr.
4 5 6 |
# File 'lib/phrender/phantom_js_session.rb', line 4 def stderr @stderr end |
#stdin ⇒ Object
Returns the value of attribute stdin.
2 3 4 |
# File 'lib/phrender/phantom_js_session.rb', line 2 def stdin @stdin end |
#stdout ⇒ Object
Returns the value of attribute stdout.
3 4 5 |
# File 'lib/phrender/phantom_js_session.rb', line 3 def stdout @stdout end |
#wait_thr ⇒ Object
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
16 17 18 |
# File 'lib/phrender/phantom_js_session.rb', line 16 def expired? (Time.now - @start_time) >= @timeout end |
#shutdown ⇒ Object
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 |