sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 7eaddc742be34c11d84903dd6da4068d77ad45a8
parent a617b3a838ce215a4581aca396adaf954c512a4c
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Thu, 27 Mar 2014 15:37:57 +0100

Merge #279: Rename SupSingleton to Redwood::Singleton

Replaces #275 and undoes #271 in favor of a Singleton class inside the
Redwood module.

Diffstat:
M lib/sup/account.rb | 2 +-
M lib/sup/buffer.rb | 2 +-
M lib/sup/contact.rb | 2 +-
M lib/sup/crypto.rb | 2 +-
M lib/sup/draft.rb | 2 +-
M lib/sup/hook.rb | 2 +-
M lib/sup/idle.rb | 2 +-
M lib/sup/index.rb | 2 +-
M lib/sup/label.rb | 2 +-
M lib/sup/logger.rb | 2 +-
M lib/sup/poll.rb | 2 +-
M lib/sup/search.rb | 2 +-
M lib/sup/sent.rb | 2 +-
M lib/sup/source.rb | 2 +-
M lib/sup/undo.rb | 2 +-
M lib/sup/update.rb | 2 +-
M lib/sup/util.rb | 62 ++++++++++++++++++++++++++++++++------------------------------
M lib/sup/util/ncurses.rb | 2 +-
18 files changed, 49 insertions(+), 47 deletions(-)
diff --git a/lib/sup/account.rb b/lib/sup/account.rb
@@ -25,7 +25,7 @@ class Account < Person
 end
 
 class AccountManager
-  include SupSingleton
+  include Redwood::Singleton
 
   attr_accessor :default_account
 
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
@@ -99,7 +99,7 @@ class Buffer
 end
 
 class BufferManager
-  include SupSingleton
+  include Redwood::Singleton
 
   attr_reader :focus_buf
 
diff --git a/lib/sup/contact.rb b/lib/sup/contact.rb
@@ -3,7 +3,7 @@
 module Redwood
 
 class ContactManager
-  include SupSingleton
+  include Redwood::Singleton
 
   def initialize fn
     @fn = fn
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -6,7 +6,7 @@ end
 module Redwood
 
 class CryptoManager
-  include SupSingleton
+  include Redwood::Singleton
 
   class Error < StandardError; end
 
diff --git a/lib/sup/draft.rb b/lib/sup/draft.rb
@@ -1,7 +1,7 @@
 module Redwood
 
 class DraftManager
-  include SupSingleton
+  include Redwood::Singleton
 
   attr_accessor :source
   def initialize dir
diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb
@@ -69,7 +69,7 @@ class HookManager
     end
   end
 
-  include SupSingleton
+  include Redwood::Singleton
 
   @descs = {}
 
diff --git a/lib/sup/idle.rb b/lib/sup/idle.rb
@@ -3,7 +3,7 @@ require 'thread'
 module Redwood
 
 class IdleManager
-  include SupSingleton
+  include Redwood::Singleton
 
   IDLE_THRESHOLD = 60
 
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -55,7 +55,7 @@ EOS
     def method_missing m; @h[m.to_s] end
   end
 
-  include SupSingleton
+  include Redwood::Singleton
 
   def initialize dir=BASE_DIR
     @dir = dir
diff --git a/lib/sup/label.rb b/lib/sup/label.rb
@@ -3,7 +3,7 @@
 module Redwood
 
 class LabelManager
-  include SupSingleton
+  include Redwood::Singleton
 
   ## labels that have special semantics. user will be unable to
   ## add/remove these via normal label mechanisms.
diff --git a/lib/sup/logger.rb b/lib/sup/logger.rb
@@ -8,7 +8,7 @@ module Redwood
 ## also keeps a record of all messages, so that adding a new sink will send all
 ## previous messages to it by default.
 class Logger
-  include SupSingleton
+  include Redwood::Singleton
 
   LEVELS = %w(debug info warn error) # in order!
 
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -3,7 +3,7 @@ require 'thread'
 module Redwood
 
 class PollManager
-  include SupSingleton
+  include Redwood::Singleton
 
   HookManager.register "before-add-message", <<EOS
 Executes immediately before a message is added to the index.
diff --git a/lib/sup/search.rb b/lib/sup/search.rb
@@ -3,7 +3,7 @@
 module Redwood
 
 class SearchManager
-  include SupSingleton
+  include Redwood::Singleton
 
   class ExpansionError < StandardError; end
 
diff --git a/lib/sup/sent.rb b/lib/sup/sent.rb
@@ -1,7 +1,7 @@
 module Redwood
 
 class SentManager
-  include SupSingleton
+  include Redwood::Singleton
 
   attr_reader :source, :source_uri
 
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -187,7 +187,7 @@ module SerializeLabelsNicely
 end
 
 class SourceManager
-  include SupSingleton
+  include Redwood::Singleton
 
   def initialize
     @sources = {}
diff --git a/lib/sup/undo.rb b/lib/sup/undo.rb
@@ -8,7 +8,7 @@ module Redwood
 ## undo the archival action
 
 class UndoManager
-  include SupSingleton
+  include Redwood::Singleton
 
   def initialize
     @@actionlist = []
diff --git a/lib/sup/update.rb b/lib/sup/update.rb
@@ -12,7 +12,7 @@ module Redwood
 ## single "view". Luckily, that's true.)
 
 class UpdateManager
-  include SupSingleton
+  include Redwood::Singleton
 
   def initialize
     @targets = {}
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -632,39 +632,41 @@ end
 ## classes that inherit this can define initialize. however, you cannot call
 ## .new on the class. To get the instance of the class, call .instance;
 ## to create the instance, call init.
-module SupSingleton
-  module ClassMethods
-    def instance; @instance; end
-    def instantiated?; defined?(@instance) && !@instance.nil?; end
-    def deinstantiate!; @instance = nil; end
-    def method_missing meth, *a, &b
-      raise "no #{name} instance defined in method call to #{meth}!" unless defined? @instance
-
-      ## if we've been deinstantiated, just drop all calls. this is
-      ## useful because threads that might be active during the
-      ## cleanup process (e.g. polling) would otherwise have to
-      ## special-case every call to a Singleton object
-      return nil if @instance.nil?
-
-      # Speed up further calls by defining a shortcut around method_missing
-      if meth.to_s[-1,1] == '='
-        # Argh! Inconsistency! Setters do not work like all the other methods.
-        class_eval "def self.#{meth}(a); @instance.send :#{meth}, a; end"
-      else
-        class_eval "def self.#{meth}(*a, &b); @instance.send :#{meth}, *a, &b; end"
-      end
+module Redwood
+  module Singleton
+    module ClassMethods
+      def instance; @instance; end
+      def instantiated?; defined?(@instance) && !@instance.nil?; end
+      def deinstantiate!; @instance = nil; end
+      def method_missing meth, *a, &b
+        raise "no #{name} instance defined in method call to #{meth}!" unless defined? @instance
+
+        ## if we've been deinstantiated, just drop all calls. this is
+        ## useful because threads that might be active during the
+        ## cleanup process (e.g. polling) would otherwise have to
+        ## special-case every call to a Singleton object
+        return nil if @instance.nil?
+
+        # Speed up further calls by defining a shortcut around method_missing
+        if meth.to_s[-1,1] == '='
+          # Argh! Inconsistency! Setters do not work like all the other methods.
+          class_eval "def self.#{meth}(a); @instance.send :#{meth}, a; end"
+        else
+          class_eval "def self.#{meth}(*a, &b); @instance.send :#{meth}, *a, &b; end"
+        end
 
-      @instance.send meth, *a, &b
-    end
-    def init *args
-      raise "there can be only one! (instance)" if instantiated?
-      @instance = new(*args)
+        @instance.send meth, *a, &b
+      end
+      def init *args
+        raise "there can be only one! (instance)" if instantiated?
+        @instance = new(*args)
+      end
     end
-  end
 
-  def self.included klass
-    klass.private_class_method :allocate, :new
-    klass.extend ClassMethods
+    def self.included klass
+      klass.private_class_method :allocate, :new
+      klass.extend ClassMethods
+    end
   end
 end
 
diff --git a/lib/sup/util/ncurses.rb b/lib/sup/util/ncurses.rb
@@ -116,7 +116,7 @@ module Ncurses
     # Empty singleton that
     # keeps GC from going crazy.
     class Empty < CharCode
-      include SupSingleton
+      include Redwood::Singleton
 
       ## Wrap methods that may change us
       ## and generate new object instead.