aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 03:35:33 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 03:35:33 -0700
commit2aff2bb01bd08872247785bca63b72a26fa60159 (patch)
tree6432456b7119c9349ed63a799a00d1509185e8c4
parentacc8aebe98593e3e0ea6938fe2c3512472c0da91 (diff)
downloaddinobot-2aff2bb01bd08872247785bca63b72a26fa60159.tar.gz
dinobot-2aff2bb01bd08872247785bca63b72a26fa60159.tar.xz
Improve and clean up load_module.
-rw-r--r--dinobot.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/dinobot.rb b/dinobot.rb
index 02c2184..947dfcd 100644
--- a/dinobot.rb
+++ b/dinobot.rb
@@ -107,14 +107,24 @@ module Dinobot
end
def load_module(mod)
- file = Dir.entries(File.dirname(__FILE__)).find { |x| x == mod.to_s.downcase + ".rb" }
+ mod = mod.downcase
+ puts "== Loading module: #{mod}."
- if file
- puts "== Loading #{mod}."
+ file = Dir.entries(File.dirname(__FILE__))
+ .find { |x| x == mod.to_s + ".rb" }
- load file
- @modules[mod.downcase] = eval("Dinobot::#{mod}").new
+ unless file
+ puts "== Failed to load module: #{mod} (File #{mod}.rb not found)."
+
+ return false
end
+
+ load file
+
+ m = Dinobot.const_get(Dinobot.constants.find { |x| x.downcase == mod })
+ @modules[mod] = m.new
+
+ puts "== Loaded module: #{mod} (#{m})."
end
end
end