output_buffer = StringIO.new()
$stdout = output_buffer
-plugin_module.includers.each do |plugin_module_includer|
- plugin = plugin_module_includer.new(cfg)
-
- if cfg.i_mean_business then
- runner = plugin.runner().new()
- else
- runner = plugin.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, *ARGV)
-end
+plugin_module.run(cfg, *ARGV)
# Restore stdout, and print the header plus whatever the plugins
# produced if they produced anything. If they didn't, we avoid
# 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
+ 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)
# Plugins for moving (renaming) users.
#
- def MvPlugin.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 MvPlugin.includers
- return @includers
- end
+ extend Plugin::Run
- def runner()
+ def self.runner()
return MvRunner
end
- def dummy_runner()
+ def self.dummy_runner()
return MvDummyRunner
end
require 'rm/rm_plugin'
module PrunePlugin
- include RmPlugin
-
#
# Plugins for the removal of leftover non-PostfixAdmin users,
# i.e. after an user has been removed from the PostfixAdmin
# database.
#
+ include RmPlugin
+ extend Plugin::Run
- def PrunePlugin.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 PrunePlugin.includers
- return @includers
- end
-
- def runner()
+ def self.runner()
return PruneRunner
end
- def dummy_runner
+ def self.dummy_runner
return PruneDummyRunner
end
+require 'common/plugin.rb'
+
module RmPlugin
#
# Plugins for the removal of users.
#
- def RmPlugin.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 RmPlugin.includers
- return @includers
- end
+ extend Plugin::Run
- def runner()
+ def self.runner()
return RmRunner
end
- def dummy_runner()
+ def self.dummy_runner()
return RmDummyRunner
end