aboutsummaryrefslogtreecommitdiff
path: root/dinobot.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 04:02:47 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 04:02:47 -0700
commitb507db60c3901ee81a879114982342cddecde017 (patch)
treee0b0255bdcf6128e4f827b34b791ba8b73695bce /dinobot.rb
parent2aff2bb01bd08872247785bca63b72a26fa60159 (diff)
downloaddinobot-b507db60c3901ee81a879114982342cddecde017.tar.gz
dinobot-b507db60c3901ee81a879114982342cddecde017.tar.xz
Better error handling in load_module.
Diffstat (limited to 'dinobot.rb')
-rw-r--r--dinobot.rb25
1 files changed, 11 insertions, 14 deletions
diff --git a/dinobot.rb b/dinobot.rb
index 947dfcd..866396e 100644
--- a/dinobot.rb
+++ b/dinobot.rb
@@ -107,24 +107,21 @@ module Dinobot
end
def load_module(mod)
- mod = mod.downcase
- puts "== Loading module: #{mod}."
+ mod = mod.downcase.intern
+ puts "== Loading module: #{mod}"
- file = Dir.entries(File.dirname(__FILE__))
- .find { |x| x == mod.to_s + ".rb" }
+ file = "#{mod}.rb"
- unless file
- puts "== Failed to load module: #{mod} (File #{mod}.rb not found)."
+ begin
+ load file
- return false
- end
-
- load file
+ m = Dinobot.const_get(Dinobot.constants.find { |x| x.downcase == mod })
+ @modules[mod] = m.new
- m = Dinobot.const_get(Dinobot.constants.find { |x| x.downcase == mod })
- @modules[mod] = m.new
-
- puts "== Loaded module: #{mod} (#{m})."
+ puts "== Loaded module: #{mod} (#{m})"
+ rescue LoadError, StandardError => e
+ puts "== Failed to load module: #{mod} (#{e.message})"
+ end
end
end
end