From: Michael Orlitzky Date: Sun, 26 Dec 2010 20:28:43 +0000 (-0500) Subject: Generalize the plugin mechanism with a Plugin module that knows when it's included. X-Git-Tag: 0.0.1~131 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=commitdiff_plain;h=8f4b4a7c4072feee31e3aefb1751d0d104e5d3ba Generalize the plugin mechanism with a Plugin module that knows when it's included. --- diff --git a/bin/mailshears b/bin/mailshears index 6e84751..abf46cc 100755 --- a/bin/mailshears +++ b/bin/mailshears @@ -34,9 +34,12 @@ require 'bin/configuration' # And the necessary classes. require 'src/errors.rb' require 'src/exit_codes.rb' -require 'src/dovecot_mailstore' require 'src/postfixadmin_db' +Configuration::PLUGINS.each do |plugin_file| + require "src/plugins/#{plugin_file}" +end + pgadb = PostfixadminDb.new(Configuration::DBHOST, Configuration::DBPORT, Configuration::DBOPTS, @@ -63,9 +66,7 @@ rescue DatabaseError => e end -Configuration::PLUGINS.each do |plugin_name| - # Convert a string into a class. - plugin_class = Kernel.const_get(plugin_name) +Plugin.includers.each do |plugin_class| plugin = plugin_class.new() begin diff --git a/src/plugin.rb b/src/plugin.rb new file mode 100644 index 0000000..2d0ded0 --- /dev/null +++ b/src/plugin.rb @@ -0,0 +1,52 @@ +# All plugins should include this module. It defines the basic +# 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 + + def Plugin.includers + return @includers + end + + def describe_domain(domain) + # Provide a "description" of the domain. This is output along + # with the domain name and can be anything of use to the system + # administrator. + raise NotImplementedError + end + + def describe_account(account) + # Provide a "description" of the account. This is output along + # with the domain name and can be anything of use to the system + # administrator. + raise NotImplementedError + end + + def delete_domain(domain) + # Delete the given domain. + raise NotImplementedError + end + + def delete_account(account) + # Delete the given account. + raise NotImplementedError + end + + def get_leftover_domains(db_domains) + # Given a list of domains, determine which domains belonging to this plugin + # are not contained in the given list. + raise NotImplementedError + end + + def get_leftover_accounts(db_accounts) + # Given a list of accounts, determine which accounts belonging to this plugin + # are not contained in the given list. + raise NotImplementedError + end +end diff --git a/src/plugins/dovecot_mailstore.rb b/src/plugins/dovecot_mailstore.rb index ee12da9..7706570 100644 --- a/src/plugins/dovecot_mailstore.rb +++ b/src/plugins/dovecot_mailstore.rb @@ -1,9 +1,12 @@ require 'src/errors' require 'src/filesystem' require 'src/mailstore' +require 'src/plugin' class DovecotMailstore < Mailstore + include Plugin + def initialize @domain_root = Configuration::MAIL_ROOT end