1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
9 BASE_DIR = File.expand_path(File.dirname(__FILE__))
11 NoPluginFound = Class.new(Exception)
14 # load all ruby files in subdirectories
15 Dir[File.join(BASE_DIR, '*')].each do |f|
17 Dir[File.join(f, '*.rb')].each do |rb_file|
24 ObjectSpace::each_object(Class) do |k|
25 if k.include?(Plugin) and k.plugin_name
26 @plugins[k.plugin_name] = k
32 @plugins.each_value(&blk)
35 def get_matching(interface, keywords = [])
36 plugins = get_all_matching(interface).
37 sort_by {|x| x.score(keywords) }
39 raise NoPluginFound if plugins.empty?
43 def get_all_matching(interface)
44 @plugins.values.reject {|x| not x.implements?(interface) }
49 alias :internal_new :new
52 @instance ||= PluginLoader.internal_new