Class: Crabfarm::PhantomRunner
- Inherits:
-
Object
- Object
- Crabfarm::PhantomRunner
- Defined in:
- lib/crabfarm/phantom_runner.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(_config = {}) ⇒ PhantomRunner
constructor
A new instance of PhantomRunner.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(_config = {}) ⇒ PhantomRunner
Returns a new instance of PhantomRunner.
8 9 10 11 |
# File 'lib/crabfarm/phantom_runner.rb', line 8 def initialize(_config={}) @config = _config; @pid = nil end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/crabfarm/phantom_runner.rb', line 6 def port @port end |
Instance Method Details
#start ⇒ Object
13 14 15 16 17 |
# File 'lib/crabfarm/phantom_runner.rb', line 13 def start find_available_port @pid = Process.spawn({}, phantomjs_cmd) wait_for_server end |
#stop ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/crabfarm/phantom_runner.rb', line 19 def stop unless @pid.nil? Process.kill("TERM", @pid) Process.wait @pid @pid = nil end end |