X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fplugin.rb;h=272f0df56749419e7f5dc14843232544ac5ee0e8;hp=ed4ea004041a8986a151783707ffec1ff939815f;hb=861e51dd6a409cb41fa6fdac3f49195acccc6541;hpb=6f2bc0181c6bb900e37d04ea722beec54486b87e diff --git a/lib/common/plugin.rb b/lib/common/plugin.rb index ed4ea00..272f0df 100644 --- a/lib/common/plugin.rb +++ b/lib/common/plugin.rb @@ -2,26 +2,50 @@ # operations that all plugins are supposed to support. module Plugin - def Plugin.included(c) - # Callback, called whenever another class or module includes this - # one. The parameter given is the name of the class or module - # that included us. - @includers ||= [] - @includers << c - end + module Run + # Module methods, meant to be extended. Includers can explicitly + # extend this to get a run() method defined in terms of their own + # runner() and dummy_runner() methods. - def Plugin.includers - return @includers - end + def included(c) + # Callback, called whenever another class or module includes this + # one. The parameter given is the name of the class or module + # that included us. + @includers ||= [] + @includers << c + end - def runner() - # The Runner associated with this plugin. - raise NotImplementedError - end + def includers + @includers ||= [] + return @includers + end - def dummy_runner() - # The RummyRunner associated with this plugin. - raise NotImplementedError + def runner() + # The Runner associated with this plugin. + raise NotImplementedError + end + + def dummy_runner() + # The RummyRunner associated with this plugin. + raise NotImplementedError + end + + def run(cfg, *args) + includers().each do |includer| + plugin = includer.new(cfg) + + if cfg.i_mean_business then + runner = runner().new() + else + runner = dummy_runner().new() + end + + # The splat passes the correct (we hope) number of arguments to the + # appropriate runner. The Rm(Dummy)Runner have splats on their + # *target arguments as well, to turn ARGV back into an array. + runner.run(plugin, *args) + end + end end def describe_domain(domain)