class Command

The Command class encapsulates a TeensyMud command

Attributes

cmd[R]
help[R]
name[R]

Public Class Methods

load() click to toggle source

load builds a command lookup trie from the commands listed in a yaml config file and in the and then defines/redefines them on the GameObject classes.

return

A trie of commands (see TernaryTrie class)

# File lib/command.rb, line 37
def self.load
  @log.info "Loading commands..."

  # first load the commands for objects
  ocmdtable = TernaryTrie.new
  if options['object_interface'] && !options['object_interface'].empty?
    options['object_interface'].each do |i|
      cmds = YAML::load_file("cmd/#{i}.yaml")
      cmds.each do |c|
        Kernel::load("cmd/#{i}/#{c.cmd}.rb")
        ocmdtable.insert(c.name, c)
      end
      GameObject.send(:include,ObjCmd)
    end
  else
    @log.warn "No command interfaces for GameObject"
  end

  # now load the commands for characters
  cmdtable = TernaryTrie.new
  if options['character_interface'] && !options['character_interface'].empty?
    options['character_interface'].each do |i|
      cmds = YAML::load_file("cmd/#{i}.yaml")
      cmds.each do |c|
        Kernel::load("cmd/#{i}/#{c.cmd}.rb")
        cmdtable.insert(c.name, c)
      end
      Character.send(:include,Cmd)
    end
  else
    @log.error "No command interfaces for Character"
  end

  @log.info "Done."
  return cmdtable, ocmdtable
rescue Exception
  @log.error $!
end
new(cmd, name, help) click to toggle source

Create a command

# File lib/command.rb, line 29
def initialize(cmd, name, help)
  @cmd,@name,@help=cmd,name,help
end
options() click to toggle source

We need options at class level

# File lib/command.rb, line 77
def self.options
  Configuration.instance.options
end