class Drudge::Kit

A kit is a set of commands that can be dispatched to

Attributes

commands[RW]

the list of commands the kit hsa

name[RW]

the name of the kit

Public Class Methods

new(name, commands = []) click to toggle source
# File lib/drudge/kit.rb, line 18
def initialize(name, commands = [])
  @name, @commands = name.to_sym, commands
end

Public Instance Methods

argument_parser() click to toggle source

returns the argument parser for this kit

# File lib/drudge/kit.rb, line 34
def argument_parser
  commands.map { |c| (command(name) > command(c.name) > commit(c.argument_parser)).collated_arguments }
          .reduce { |p1, p2| p1 | p2 }
end
dispatch(command_name, *args) click to toggle source

Dispatches a command within the kit The first argument is the command name

# File lib/drudge/kit.rb, line 24
def dispatch(command_name, *args)
  command = find_command(command_name) rescue nil

  raise UnknownCommandError.new(name), "A command is required" unless command

  command.dispatch *args
  
end

Private Instance Methods

find_command(command_name) click to toggle source
# File lib/drudge/kit.rb, line 41
def find_command(command_name)
  commands.find { |c| c.name == command_name.to_sym }
end