X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fplugin.rb;h=81e1fbb6248e323f315c0108f7c9e11f5bb72b8c;hp=b0b57505873665a856dcf7ade0eafc4b82cf266a;hb=41b5e74bedf1def1ef22cd77ed26d87fae859a13;hpb=72696d3f6e95ef773af9727e9c3459b9038b0fc2 diff --git a/lib/common/plugin.rb b/lib/common/plugin.rb index b0b5750..81e1fbb 100644 --- a/lib/common/plugin.rb +++ b/lib/common/plugin.rb @@ -2,16 +2,49 @@ # 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 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 includers + return @includers + end + + def runner() + # The Runner associated with this plugin. + raise NotImplementedError + end - def Plugin.includers - return @includers + 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)