From be5d914984e767ce1a718b84d0bad1c88d9f8ea3 Mon Sep 17 00:00:00 2001 From: Raine Virta Date: Fri, 27 Feb 2009 21:30:40 +0200 Subject: plugins: refactor plugin scanning Refactor plugin scanning for cleaner distinction between core modules and plugins. --- lib/rbot/plugins.rb | 66 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 27 deletions(-) mode change 100644 => 100755 lib/rbot/plugins.rb (limited to 'lib') diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb old mode 100644 new mode 100755 index 5c5cdddc..00fc4234 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -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| -- cgit v1.2.3