]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/common/agendav_plugin.rb
Document everything with YARD and fix some bugs along the way.
[mailshears.git] / lib / common / agendav_plugin.rb
index fc19d3d60fd45fccfec195ca745de1c0d7b5b3b5..8eb73c19e029259426f9958e94f81af373ab0a14 100644 (file)
@@ -1,12 +1,18 @@
 require 'common/plugin'
 require 'common/user'
 
+# Code that all Agendav plugins ({AgendavPrune}, {AgendavRm},
+# {AgendavMv}) share.
 module AgendavPlugin
-  # Code that all Agendav plugins (Prune, Rm, Mv...) will
-  # share.  That is, we implement the Plugin interface.
+
+  # We implement the Plugin "interface."
   include Plugin
 
 
+  # Initialize this Agendav {Plugin} with values in *cfg*.
+  #
+  # @param cfg [Configuration] the configuration for this plugin.
+  #
   def initialize(cfg)
     @db_host = cfg.agendav_dbhost
     @db_port = cfg.agendav_dbport
@@ -18,46 +24,27 @@ module AgendavPlugin
   end
 
 
-  def describe_domain(domain)
-    return domain.to_s()
-  end
-
-  def describe_user(user)
-    return user.to_s()
-  end
-
-
+  # Return a list of Agendav users.
+  #
+  # @return [Array<User>] a list of users contained in the
+  #   Agendav database.
+  #
   def list_users()
-    #
-    # Produce a list of AgenDAV users. This is public because it's
-    # useful in testing.
-    #
     users = []
 
-    # Just assume PostgreSQL for now.
-    begin
-      connection = PGconn.connect(@db_host,
-                                  @db_port,
-                                  @db_opts,
-                                  @db_tty,
-                                  @db_name,
-                                  @db_user,
-                                  @db_pass)
+    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
+                                @db_name, @db_user, @db_pass)
 
-      sql_query  = '(SELECT username FROM prefs)'
-      sql_query += 'UNION'
-      sql_query += '(SELECT user_from FROM shared);'
+    sql_query  = '(SELECT username FROM prefs)'
+    sql_query += 'UNION'
+    sql_query += '(SELECT user_from FROM shared);'
 
-      connection.query(sql_query) do |result|
-        users = result.field_values('username')
-      end
-
-      connection.close()
-    rescue PGError => e
-      # Pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
+    connection.query(sql_query) do |result|
+      users = result.field_values('username')
     end
 
+    connection.close()
+
     return users.map{ |u| User.new(u) }
   end