class Expedite::Commands

Public Class Methods

current() click to toggle source
# File lib/expedite/commands.rb, line 6
def self.current
  @current ||= Commands.new
end
lookup(name) click to toggle source
# File lib/expedite/commands.rb, line 10
def self.lookup(name)
  self.current.lookup(name)
end
new() click to toggle source
# File lib/expedite/commands.rb, line 33
def initialize
  reset
end
register(name, klass_or_nil = nil, **named_options, &block) click to toggle source

Registers a command. If multiple commands are registered with the same name, the last one takes precedence.

name

Name of the command. Expedite internal commands are prefixed with “expedite/”

klass_or_nil

Class of the command. If omitted, will default to Expedite::Command::Basic.

named_options

Command options. Passed to the initializer.

# File lib/expedite/commands.rb, line 23
def self.register(name, klass_or_nil = nil, **named_options, &block)
  self.current.register(name, klass_or_nil, **named_options, &block)
end
reset() click to toggle source

Restores existing registrations to default

# File lib/expedite/commands.rb, line 29
def self.reset
  self.current.reset
end

Public Instance Methods

lookup(name) click to toggle source
# File lib/expedite/commands.rb, line 37
def lookup(name)
   ret = @registrations[name]
   raise NotImplementedError, "Command #{name.inspect} not found" if ret.nil?
   ret
end
register(name, klass_or_nil = nil, **named_options, &block) click to toggle source
# File lib/expedite/commands.rb, line 43
def register(name, klass_or_nil = nil, **named_options, &block)
  cmd = if klass_or_nil.nil?
    Command::Basic.new(**named_options, &block)
  else
    klass_or_nil.new(**named_options)
  end

  @registrations[name] = cmd
end
reset() click to toggle source
# File lib/expedite/commands.rb, line 53
def reset
  @registrations = {}

  # Default registrations
  register("expedite/boot", Expedite::Command::Boot)

  nil
end