Pass a Configuration object to each plugin's initialize().
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 7 Oct 2013 14:20:46 +0000 (10:20 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 7 Oct 2013 14:20:46 +0000 (10:20 -0400)
bin/mailshears
lib/common/agendav_plugin.rb
lib/common/configuration.rb
lib/common/davical_plugin.rb
lib/common/dovecot_plugin.rb
lib/common/postfixadmin_plugin.rb
lib/common/roundcube_plugin.rb
lib/prune/prune_runner.rb

index 389c1774a52dbf96dc9936bb07515404da970ee6..28c165cee765492bbaeb28f91ae76a54da750631 100755 (executable)
@@ -110,7 +110,7 @@ output_buffer = StringIO.new()
 $stdout = output_buffer
 
 plugin_class.includers.each do |plugin_class_includer|
-  plugin = plugin_class_includer.new()
+  plugin = plugin_class_includer.new(cfg)
 
   if cfg.i_mean_business then
     runner = runner_class.new()
index 88de0d79ded0ca11897f1fbf4a60bf0162db2d92..a29f3ae84a7df1d712badacfc53bc3d3f245b345 100644 (file)
@@ -6,8 +6,7 @@ module AgendavPlugin
   include Plugin
 
 
-  def initialize()
-    cfg = Configuration.new()
+  def initialize(cfg)
     @db_host = cfg.agendav_dbhost
     @db_port = cfg.agendav_dbport
     @db_opts = cfg.agendav_dbopts
index 43ef03b3e726f5fd694b44c6bac1a4416a0e5d52..c9bf9ea3e04fbd5959fee48b3ad361adaf93b02e 100644 (file)
@@ -5,13 +5,13 @@ class Configuration
   USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml'
   @dict = {}
 
-  def initialize()
+  def initialize(path = USERCONF_PATH)
     cfg = default_configuration()
 
     # Now, load the user configuration which will override the
     # variables defined above.
     begin
-      user_config = YAML.load(File.open(USERCONF_PATH))
+      user_config = YAML.load(File.open(path))
 
       # Write our own update() method for Ruby 1.8.
       user_config.each do |key, value|
@@ -49,7 +49,11 @@ class Configuration
     d['postfixadmin_dbpass'] = ''
     d['postfixadmin_dbname'] = 'postfixadmin'
 
-    d['plugins'] = ['postfixadmin', 'dovecot', 'roundcube']
+    d['plugins'] = ['postfixadmin',
+                    'dovecot',
+                    'roundcube',
+                    'agendav',
+                    'davical']
 
     d['mail_root'] = '/var/spool/mail/vhosts'
 
index c8a67261c16c23cad6da901128cd281e7e384076..afd1d883e66115c32964fb9f9cd61f58c0622a93 100644 (file)
@@ -5,8 +5,7 @@ module DavicalPlugin
   # is, we implement the Plugin interface.
   include Plugin
 
-  def initialize()
-    cfg = Configuration.new()
+  def initialize(cfg)
     @db_host = cfg.davical_dbhost
     @db_port = cfg.davical_dbport
     @db_opts = cfg.davical_dbopts
index 2496bae2eade64be5889c4a5057b8ac00e4b5228..ab5a40930400af057229ded188d40516cc88b866 100644 (file)
@@ -6,8 +6,7 @@ module DovecotPlugin
   # share.  That is, we implement the Plugin interface.
   include Plugin
 
-  def initialize
-    cfg = Configuration.new()
+  def initialize(cfg)
     @domain_root = cfg.mail_root
   end
 
index 4bfda9dcdece7e7216856b17ff96745c031313e7..7a1985202cc343af0301518dc9a9e94abf03c799 100644 (file)
@@ -6,9 +6,7 @@ module PostfixadminPlugin
   # share.  That is, we implement the Plugin interface.
   include Plugin
 
-  def initialize()
-
-    cfg = Configuration.new()
+  def initialize(cfg)
     @db_host = cfg.postfixadmin_dbhost
     @db_port = cfg.postfixadmin_dbport
     @db_opts = cfg.postfixadmin_dbopts
index 8e9d62259d78fd9819bc2ef77bc97c3c2b0fa96c..8575a11eae4e3ee214ba6a7d1cc317a0c018951a 100644 (file)
@@ -5,8 +5,7 @@ module RoundcubePlugin
   # That is, we implement the Plugin interface.
   include Plugin
 
-  def initialize()
-    cfg = Configuration.new()
+  def initialize(cfg)
     @db_host = cfg.roundcube_dbhost
     @db_port = cfg.roundcube_dbport
     @db_opts = cfg.roundcube_dbopts
index 74455d6b2ba8903655ce385b8e4c16d81ad4ccf6..acc8828ba11be426a0c0ad90b1fe991c25f7154a 100644 (file)
@@ -10,7 +10,8 @@ class PruneRunner
     # We don't want to check the PostfixAdmin database against itself.
     return if plugin.class == PostfixadminPrune
 
-    pfa = PostfixadminPrune.new()
+    cfg = Configuration.new()
+    pfa = PostfixadminPrune.new(cfg)
 
     db_users = pfa.list_users()
     db_domains = pfa.list_domains()