Class: Opal::CliRunners::Chrome

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/cli_runners/chrome.rb

Constant Summary

SCRIPT_PATH =
File.expand_path('chrome.js', __dir__).freeze
DEFAULT_CHROME_HOST =
'localhost'
DEFAULT_CHROME_PORT =
9222

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Chrome

Returns a new instance of Chrome



15
16
17
# File 'opal/lib/opal/cli_runners/chrome.rb', line 15

def initialize(options)
  @output = options.fetch(:output, $stdout)
end

Instance Attribute Details

#exit_statusObject (readonly)

Returns the value of attribute exit_status



18
19
20
# File 'opal/lib/opal/cli_runners/chrome.rb', line 18

def exit_status
  @exit_status
end

#outputObject (readonly)

Returns the value of attribute output



18
19
20
# File 'opal/lib/opal/cli_runners/chrome.rb', line 18

def output
  @output
end

Instance Method Details

#run(code, _argv) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'opal/lib/opal/cli_runners/chrome.rb', line 20

def run(code, _argv)
  with_chrome_server do
    cmd = [
      'env',
      "CHROME_HOST=#{chrome_host}",
      "CHROME_PORT=#{chrome_port}",
      'node',
      SCRIPT_PATH
    ]

    IO.popen(cmd, 'w', out: output) do |io|
      io.write(code)
    end

    @exit_status = $?.exitstatus
  end
end