Module: Opal::CliRunners

Defined in:
opal/lib/opal/cli_runners.rb,
opal/lib/opal/cli_runners/chrome.rb,
opal/lib/opal/cli_runners/nodejs.rb,
opal/lib/opal/cli_runners/server.rb,
opal/lib/opal/cli_runners/nashorn.rb,
opal/lib/opal/cli_runners/applescript.rb

Overview

Opal::CliRunners is the register in which JavaScript runners can be defined for use by Opal::CLI. Runners will be called via the #call method and passed a Hash containing the following keys:

  • options: a hash of options for the runner
  • output: an IO-like object responding to #write and #puts
  • argv: is the arguments vector coming from the CLI that is being forwarded to the program
  • builder: the current instance of Opal::Builder

Runners can be registered using #register_runner(name, runner).

Defined Under Namespace

Classes: Applescript, Chrome, Nashorn, Nodejs, RunnerError, Server

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



23
24
25
# File 'opal/lib/opal/cli_runners.rb', line 23

def self.[](name)
  @register[name.to_sym]
end

.[]=(name, runner) ⇒ Object



27
28
29
30
# File 'opal/lib/opal/cli_runners.rb', line 27

def self.[]=(name, runner)
  warn "Overwriting Opal CLI runner: #{name}" if @register.key? name.to_sym
  @register[name.to_sym] = runner
end

.register_legacy_runner(klass_name, *names) ⇒ Object

Legacy runners



59
60
61
62
63
64
65
66
67
68
69
# File 'opal/lib/opal/cli_runners.rb', line 59

def self.register_legacy_runner(klass_name, *names)
  runner = ->(data) {
    klass = const_get(klass_name)
    runner = klass.new((data[:options] || {}).merge(output: data[:output]))
    builder = data[:builder]
    compiled_source = builder.to_s + "\n" + builder.source_map.to_data_uri_comment
    runner.run(compiled_source, data[:argv])
    runner.exit_status
  }
  names.each { |name| self[name] = runner }
end

.register_runner(name, runner) ⇒ Object

Parameters:

  • name (Symbol)

    the name at which the runner can be reached

  • runner (#call)

    a callable object that will act as the "runner"



38
39
40
41
# File 'opal/lib/opal/cli_runners.rb', line 38

def self.register_runner(name, runner)
  self[name] = runner
  nil
end

.to_hObject



32
33
34
# File 'opal/lib/opal/cli_runners.rb', line 32

def self.to_h
  @register
end