Class: Butler::IRC::Parser::Commands
- Inherits:
-
Object
- Object
- Butler::IRC::Parser::Commands
show all
- Includes:
- Log::Comfort
- Defined in:
- lib/butler/irc/parser/commands.rb
Constant Summary
collapse
- BasePath =
File.expand_path(File.dirname(__FILE__))
Instance Attribute Summary
Attributes included from Log::Comfort
#logger
Instance Method Summary
collapse
#debug, #error, #exception, #fail, #info, #log, #warn
Constructor Details
#initialize(*files) ⇒ Commands
Returns a new instance of Commands.
23
24
25
26
|
# File 'lib/butler/irc/parser/commands.rb', line 23
def initialize(*files)
@commands = Hash.new { |h,k| raise IndexError, "Unknown command #{k}" }
load(*files)
end
|
Instance Method Details
#[](raw) ⇒ Object
46
47
48
|
# File 'lib/butler/irc/parser/commands.rb', line 46
def [](raw)
@commands[raw.downcase]
end
|
#add(raw, *args, &proc) ⇒ Object
36
37
38
39
|
# File 'lib/butler/irc/parser/commands.rb', line 36
def add(raw, *args, &proc)
raise IndexError, "Command #{raw} is already registered. Did you want 'alter'?" if @commands.has_key?(raw)
@commands[raw.downcase] = Command.new(raw, *args, &proc)
end
|
#alter(raw, *args, &proc) ⇒ Object
41
42
43
44
|
# File 'lib/butler/irc/parser/commands.rb', line 41
def alter(raw, *args, &proc)
raise IndexError, "Command #{raw} is not registered. Did you want 'add'?" unless @commands.has_key?(raw)
@commands[raw.downcase] = Command.new(raw, *args, &proc)
end
|
#inspect ⇒ Object
50
51
52
|
# File 'lib/butler/irc/parser/commands.rb', line 50
def inspect
"#<%s:0x%x>" % [self.class, object_id]
end
|
#load(*files) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/butler/irc/parser/commands.rb', line 28
def load(*files)
raise ArgumentError, "Requires at least one argument." if files.empty?
files.each { |file|
file = "#{BasePath}/#{file}.rb" unless file.include?('/')
instance_eval(File.read(file), file)
}
end
|