- 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
+ 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
+ @includers ||= []
+ return @includers
+ end
+
+ def runner()
+ # The Runner associated with this plugin.
+ raise NotImplementedError
+ end
+
+ def dummy_runner()
+ # The DummyRunner 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(cfg, plugin, *args)
+ end
+ end