]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Generalize the plugin mechanism with a Plugin module that knows when it's included.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 26 Dec 2010 20:28:43 +0000 (15:28 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 26 Dec 2010 20:28:43 +0000 (15:28 -0500)
bin/mailshears
src/plugin.rb [new file with mode: 0644]
src/plugins/dovecot_mailstore.rb

index 6e84751161ae0566387a8a5e34b0f4876fdb9bfb..abf46cc9c188da4be8f0326345588d2fddb186da 100755 (executable)
@@ -34,9 +34,12 @@ require 'bin/configuration'
 # And the necessary classes.
 require 'src/errors.rb'
 require 'src/exit_codes.rb'
 # And the necessary classes.
 require 'src/errors.rb'
 require 'src/exit_codes.rb'
-require 'src/dovecot_mailstore'
 require 'src/postfixadmin_db'
 
 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,
 pgadb = PostfixadminDb.new(Configuration::DBHOST,
                            Configuration::DBPORT,
                            Configuration::DBOPTS,
@@ -63,9 +66,7 @@ rescue DatabaseError => e
 end
 
 
 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
   plugin = plugin_class.new()
 
   begin
diff --git a/src/plugin.rb b/src/plugin.rb
new file mode 100644 (file)
index 0000000..2d0ded0
--- /dev/null
@@ -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
index ee12da905412a207f9e092b60507382fb84ab16d..7706570b2e5005a1babd77bfffddac5e89bd988c 100644 (file)
@@ -1,9 +1,12 @@
 require 'src/errors'
 require 'src/filesystem'
 require 'src/mailstore'
 require 'src/errors'
 require 'src/filesystem'
 require 'src/mailstore'
+require 'src/plugin'
 
 class DovecotMailstore < Mailstore
 
 
 class DovecotMailstore < Mailstore
 
+  include Plugin
+  
   def initialize
     @domain_root = Configuration::MAIL_ROOT
   end
   def initialize
     @domain_root = Configuration::MAIL_ROOT
   end