From b507db60c3901ee81a879114982342cddecde017 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 14 Apr 2014 04:02:47 -0700 Subject: Better error handling in load_module. --- dinobot.rb | 25 +++++++++++-------------- 1 file 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 -- cgit v1.2.3-70-g09d2