diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 04:02:47 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 04:02:47 -0700 |
commit | b507db60c3901ee81a879114982342cddecde017 (patch) | |
tree | e0b0255bdcf6128e4f827b34b791ba8b73695bce /dinobot.rb | |
parent | 2aff2bb01bd08872247785bca63b72a26fa60159 (diff) | |
download | dinobot-b507db60c3901ee81a879114982342cddecde017.tar.gz dinobot-b507db60c3901ee81a879114982342cddecde017.tar.xz |
Better error handling in load_module.
Diffstat (limited to 'dinobot.rb')
-rw-r--r-- | dinobot.rb | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -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 |