From: Michael Orlitzky Date: Mon, 7 Oct 2013 14:20:46 +0000 (-0400) Subject: Pass a Configuration object to each plugin's initialize(). X-Git-Tag: 0.0.1~77 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=365d681f1ef45bd3f5f2c9dded07108bdd75a1ff;p=mailshears.git Pass a Configuration object to each plugin's initialize(). --- diff --git a/bin/mailshears b/bin/mailshears index 389c177..28c165c 100755 --- a/bin/mailshears +++ b/bin/mailshears @@ -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() diff --git a/lib/common/agendav_plugin.rb b/lib/common/agendav_plugin.rb index 88de0d7..a29f3ae 100644 --- a/lib/common/agendav_plugin.rb +++ b/lib/common/agendav_plugin.rb @@ -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 diff --git a/lib/common/configuration.rb b/lib/common/configuration.rb index 43ef03b..c9bf9ea 100644 --- a/lib/common/configuration.rb +++ b/lib/common/configuration.rb @@ -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' diff --git a/lib/common/davical_plugin.rb b/lib/common/davical_plugin.rb index c8a6726..afd1d88 100644 --- a/lib/common/davical_plugin.rb +++ b/lib/common/davical_plugin.rb @@ -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 diff --git a/lib/common/dovecot_plugin.rb b/lib/common/dovecot_plugin.rb index 2496bae..ab5a409 100644 --- a/lib/common/dovecot_plugin.rb +++ b/lib/common/dovecot_plugin.rb @@ -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 diff --git a/lib/common/postfixadmin_plugin.rb b/lib/common/postfixadmin_plugin.rb index 4bfda9d..7a19852 100644 --- a/lib/common/postfixadmin_plugin.rb +++ b/lib/common/postfixadmin_plugin.rb @@ -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 diff --git a/lib/common/roundcube_plugin.rb b/lib/common/roundcube_plugin.rb index 8e9d622..8575a11 100644 --- a/lib/common/roundcube_plugin.rb +++ b/lib/common/roundcube_plugin.rb @@ -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 diff --git a/lib/prune/prune_runner.rb b/lib/prune/prune_runner.rb index 74455d6..acc8828 100644 --- a/lib/prune/prune_runner.rb +++ b/lib/prune/prune_runner.rb @@ -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()