Class: Postdoc::ChromeProcess
- Inherits:
-
Object
- Object
- Postdoc::ChromeProcess
- Defined in:
- lib/postdoc/chrome_process.rb
Overview
Spins up a Chrome process.
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #client ⇒ Object
-
#initialize(port: Random.rand(1025..65535), **_options) ⇒ ChromeProcess
constructor
A new instance of ChromeProcess.
- #kill ⇒ Object
Constructor Details
#initialize(port: Random.rand(1025..65535), **_options) ⇒ ChromeProcess
Returns a new instance of ChromeProcess.
8 9 10 11 12 |
# File 'lib/postdoc/chrome_process.rb', line 8 def initialize(port: Random.rand(1025..65535), **) @port = port @pid = Process.spawn "chrome --remote-debugging-port=#{port} --headless", out: File::NULL, err: File::NULL end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
6 7 8 |
# File 'lib/postdoc/chrome_process.rb', line 6 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/postdoc/chrome_process.rb', line 6 def port @port end |
Instance Method Details
#alive? ⇒ Boolean
14 15 16 17 18 |
# File 'lib/postdoc/chrome_process.rb', line 14 def alive? @alive ||= test_socket! rescue Errno::ECONNREFUSED false end |
#client ⇒ Object
27 28 29 |
# File 'lib/postdoc/chrome_process.rb', line 27 def client Client.new port end |
#kill ⇒ Object
20 21 22 23 24 25 |
# File 'lib/postdoc/chrome_process.rb', line 20 def kill Process.kill 'INT', pid Process.wait pid rescue true end |