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 runneroutput
: an IO-like object responding to#write
and#puts
argv
: is the arguments vector coming from the CLI that is being forwarded to the programbuilder
: 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
- .[](name) ⇒ Object
- .[]=(name, runner) ⇒ Object
-
.register_legacy_runner(klass_name, *names) ⇒ Object
Legacy runners.
- .register_runner(name, runner) ⇒ Object
- .to_h ⇒ Object
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
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_h ⇒ Object
32 33 34 |
# File 'opal/lib/opal/cli_runners.rb', line 32 def self.to_h @register end |