]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
plugins: refactor plugin scanning
authorRaine Virta <rane@kapsi.fi>
Fri, 27 Feb 2009 19:30:40 +0000 (21:30 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 28 Feb 2009 00:43:45 +0000 (01:43 +0100)
Refactor plugin scanning for cleaner distinction between core modules
and plugins.

lib/rbot/plugins.rb [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 5c5cddd..00fc423
@@ -600,27 +600,31 @@ module Plugins
       debug "Core module and plugin loading paths cleared"
     end
 
-    # load plugins from pre-assigned list of directories
-    def scan
-      @failed.clear
-      @ignored.clear
-      @delegate_list.clear
-
+    def scan_botmodules(opts={})
+      type = opts[:type]
       processed = Hash.new
 
-      @bot.config['plugins.blacklist'].each { |p|
-        pn = p + ".rb"
-        processed[pn.intern] = :blacklisted
-      }
+      case type
+      when :core
+        dirs = @core_module_dirs
+      when :plugins
+        dirs = @plugin_dirs
 
-      dirs = @core_module_dirs + @plugin_dirs
-      dirs.each {|dir|
-        if(FileTest.directory?(dir))
-          d = Dir.new(dir)
-          d.sort.each {|file|
+        @bot.config['plugins.blacklist'].each { |p|
+          pn = p + ".rb"
+          processed[pn.intern] = :blacklisted
+        }
+      end
 
-            next if(file =~ /^\./)
+      dirs.each do |dir|
+        next unless FileTest.directory?(dir)
+        d = Dir.new(dir)
+        d.sort.each do |file|
+          next unless file =~ /\.rb$/
+          next if file =~ /^\./
 
+          case type
+          when :plugins
             if processed.has_key?(file.intern)
               @ignored << {:name => file, :dir => dir, :reason => processed[file.intern]}
               next
@@ -635,20 +639,28 @@ module Plugins
               @ignored << {:name => $1, :dir => dir, :reason => processed[$1.intern]}
               next
             end
+          end
+
+          did_it = load_botmodule_file("#{dir}/#{file}", "plugin")
+          case did_it
+          when Symbol
+            processed[file.intern] = did_it
+          when Exception
+            @failed << { :name => file, :dir => dir, :reason => did_it }
+          end
+        end
+      end
+    end
 
-            next unless(file =~ /\.rb$/)
+    # load plugins from pre-assigned list of directories
+    def scan
+      @failed.clear
+      @ignored.clear
+      @delegate_list.clear
 
-            did_it = load_botmodule_file("#{dir}/#{file}", "plugin")
-            case did_it
-            when Symbol
-              processed[file.intern] = did_it
-            when Exception
-              @failed <<  { :name => file, :dir => dir, :reason => did_it }
-            end
+      scan_botmodules(:type => :core)
+      scan_botmodules(:type => :plugins)
 
-          }
-        end
-      }
       debug "finished loading plugins: #{status(true)}"
       (core_modules + plugins).each { |p|
        p.methods.grep(DEFAULT_DELEGATE_PATTERNS).each { |m|