]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/common/plugin.rb
Remove mv_domain() from MvPlugin.
[mailshears.git] / lib / common / plugin.rb
index 633c8fd26d0c2f4bd467ff3d33aa3a48cc1a93fc..272f0df56749419e7f5dc14843232544ac5ee0e8 100644 (file)
@@ -2,16 +2,50 @@
 # 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 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 includers
+      @includers ||= []
+      return @includers
+    end
+
+    def runner()
+      # The Runner associated with this plugin.
+      raise NotImplementedError
+    end
 
-  def Plugin.includers
-    return @includers
+    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)
@@ -21,8 +55,8 @@ module Plugin
     raise NotImplementedError
   end
 
-  def describe_account(account)
-    # Provide a "description" of the account. This is output along
+  def describe_user(user)
+    # Provide a "description" of the user. This is output along
     # with the domain name and can be anything of use to the system
     # administrator.
     raise NotImplementedError
@@ -33,6 +67,14 @@ module Plugin
     raise NotImplementedError
   end
 
+  def user_exists(username)
+    # Does the given username exist for this plugin? We use a naive
+    # implementation here based on list_users() which is required to
+    # exist above. Plugins can override this with something fast.
+    users = list_users()
+    return users.include?(username)
+  end
+
   def list_domains_users(domains)
     # Get all usernames belonging to the given domains. If a username
     # ends in @example.com, it belongs to the domain example.com