Class Command
In: lib/command.rb
lib/command.rb
Parent: Object
Command
dot/f_7.png

The Command class encapsulates a TeensyMud command

Methods

load   load   new   new   options   options  

Attributes

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

Public Class methods

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)

[Source]

# 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

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)

[Source]

# 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

Create a command

[Source]

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

Create a command

[Source]

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

We need options at class level

[Source]

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

We need options at class level

[Source]

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

[Validate]