module Opal::CliRunners
‘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 beingforwarded to the program
-
‘builder`: a proc returning a new instance of
Opal::Builder
so itcan be re-created and pick up the most up-to-date sources
Runners can be registered using ‘#register_runner(name, runner)`.
Public Class Methods
# File lib/opal/cli_runners.rb, line 32 def self.[](name) @register[name.to_sym]&.call end
Alias a runner name
# File lib/opal/cli_runners.rb, line 68 def self.alias_runner(new_name, old_name) self[new_name.to_sym] = -> { self[old_name.to_sym] } nil end
@param name [Symbol] the name at which the runner can be reached @param runner [#call] a callable object that will act as the “runner” @param runner [Symbol] a constant name that once autoloaded will point to
a callable.
@param path [nil,String] a path for setting up autoload on the constant
# File lib/opal/cli_runners.rb, line 53 def self.register_runner(name, runner, path = nil) autoload runner, path if path @runners.push(runner.to_s) if runner.respond_to? :call self[name] = -> { runner } else self[name] = -> { const_get(runner) } end nil end
# File lib/opal/cli_runners.rb, line 26 def self.registered_runners @runners end
# File lib/opal/cli_runners.rb, line 44 def self.to_h @register end
Private Class Methods
@private
# File lib/opal/cli_runners.rb, line 37 def self.[]=(name, runner) warn "Overwriting Opal CLI runner: #{name}" if @register.key? name.to_sym @register[name.to_sym] = runner end