Module: Mchat::Command

Included in:
Repl
Defined in:
lib/mchat/command.rb,
lib/mchat/commands/help.rb,
lib/mchat/commands/join.rb,
lib/mchat/commands/name.rb,
lib/mchat/commands/quit.rb,
lib/mchat/commands/clear.rb,
lib/mchat/commands/guide.rb,
lib/mchat/commands/leave.rb,
lib/mchat/commands/channel.rb,
lib/mchat/commands/default.rb,
lib/mchat/commands/message.rb,
lib/mchat/commands/bossmode.rb,
lib/mchat/commands/channel_new.rb

Defined Under Namespace

Modules: BossMode, Channel, ChannelNew, Clear, Default, Guide, Help, Join, Leave, Message, Name, Quit

Constant Summary collapse

CommandComps =

Class ########################3

{}
CommandConditions =
[]

Class Method Summary collapse

Class Method Details

.install(cmd, *args, &block) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
# File 'lib/mchat/command.rb', line 20

def self.install(cmd, *args, &block)
  cmd = Mchat::Command.load_command(cmd) if cmd.is_a?(Symbol)
  raise MchatError, "Invalid cmd type: #{cmd.class.inspect}" unless cmd.is_a?(Module)

  include(cmd::InstanceMethods) if defined?(cmd::InstanceMethods)
  extend(cmd::ClassMethods) if defined?(cmd::ClassMethods)
  cmd.configure(self, *args, &block) if cmd.respond_to?(:configure)
end

.load_command(name) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/mchat/command.rb', line 11

def self.load_command(name)
  h = CommandComps
  unless cmd = h[name]
    require_relative "./commands/#{name}"
    raise RodaError, "command #{name} did not mount itself correctly in Mchat::Command" unless cmd = h[name]
  end
  cmd
end

.mount_command(name, mod) ⇒ Object



7
8
9
# File 'lib/mchat/command.rb', line 7

def self.mount_command(name, mod)
  CommandComps[name] = mod
end