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.
11 BASE_DIR = File.expand_path(File.dirname(__FILE__))
13 NoPluginFound = Class.new(Exception)
17 # load all ruby files in subdirectories
18 Dir[File.join(BASE_DIR, '*')].each do |f|
20 Dir[File.join(f, '*.rb')].each do |rb_file|
26 @plugins = ObjectSpace.
27 to_enum(:each_object, Class).
29 k.include?(Plugin) and k.plugin_name
37 def get_matching(interface, keywords = [])
38 plugins = get_all_matching(interface).
39 sort_by {|x| x.score(keywords) }
41 raise NoPluginFound.new("No plugins matching interface #{interface}") if plugins.empty?
45 def get_all_matching(interface)
46 @plugins.reject {|x| not x.implements?(interface) }
51 alias :internal_new :new
54 @instance ||= PluginLoader.internal_new