Introduce the concept of plugin interface.
[kaya.git] / lib / plugins / plugin.rb
blob7ff7d5a6400877603ff50d62823e89067621d660
1 module Plugin
2   module ModuleMethods
3     def included(base)
4       if base.class == Module
5         base.extend ModuleMethods
6       else
7         base.extend ClassMethods
8       end
9     end
10   end
11   
12   module ClassMethods
13     def plugin(args)
14       @plugin_data = args
15     end
16     
17     def plugin_name
18       @plugin_data[:name] if @plugin_data
19     end
20     
21     def score(keywords)
22       ((@plugin_data[:keywords] || []) & keywords).size
23     end
24     
25     def implements?(iface)
26       @plugin_data[:interface] == iface
27     end
28   end
29   
30   extend ModuleMethods
31 end