The flip side is that you have to use .init instead of .new.
end
module_function :start_cursing, :stop_cursing
-Index.new
+Index.init
begin
Index.lock
rescue Index::LockError => e
log "starting curses"
start_cursing
- bm = BufferManager.new
+ bm = BufferManager.init
Colormap.new.populate_colormap
log "initializing mail index buffer"
$terminal.wrap_at = :auto
Redwood::start
-index = Redwood::Index.new
+index = Redwood::Index.init
index.lock_or_die
$terminal.wrap_at = :auto
Redwood::start
-index = Redwood::Index.new
+index = Redwood::Index.init
Redwood::SourceManager.load_sources
say <<EOS
EOS
end
-index = Redwood::Index.new
-Redwood::SourceManager.new
+index = Redwood::Index.init
+Redwood::SourceManager.init
index.load
index.each_message :load_spam => true, :load_deleted => true, :load_killed => true do |m|
require "sup"
Redwood::start
puts "loading index..."
-index = Redwood::Index.new
+index = Redwood::Index.init
index.load
puts "loaded index of #{index.size} messages"
op = [:asis, :restore, :discard].find { |x| opts[x] } || :asis
Redwood::start
-index = Redwood::Index.new
+index = Redwood::Index.init
restored_state = if opts[:restore]
dump = {}
end
Redwood::start
-index = Redwood::Index.new
+index = Redwood::Index.init
index.lock_or_die
deleted_fp, spam_fp = nil
Redwood::start
begin
- index = Redwood::Index.new
+ index = Redwood::Index.init
index.load
source_ids = if opts[:all_sources]
end
def start
- Redwood::SentManager.new $config[:sent_source] || 'sup://sent'
- Redwood::ContactManager.new Redwood::CONTACT_FN
- Redwood::LabelManager.new Redwood::LABEL_FN
- Redwood::AccountManager.new $config[:accounts]
- Redwood::DraftManager.new Redwood::DRAFT_DIR
- Redwood::UpdateManager.new
- Redwood::PollManager.new
- Redwood::SuicideManager.new Redwood::SUICIDE_FN
- Redwood::CryptoManager.new
- Redwood::UndoManager.new
- Redwood::SourceManager.new
+ Redwood::SentManager.init $config[:sent_source] || 'sup://sent'
+ Redwood::ContactManager.init Redwood::CONTACT_FN
+ Redwood::LabelManager.init Redwood::LABEL_FN
+ Redwood::AccountManager.init $config[:accounts]
+ Redwood::DraftManager.init Redwood::DRAFT_DIR
+ Redwood::UpdateManager.init
+ Redwood::PollManager.init
+ Redwood::SuicideManager.init Redwood::SUICIDE_FN
+ Redwood::CryptoManager.init
+ Redwood::UndoManager.init
+ Redwood::SourceManager.init
end
def finish
## we have to initialize this guy first, because other classes must
## reference it in order to register hooks, and they do that at parse
## time.
-Redwood::HookManager.new Redwood::HOOK_DIR
+Redwood::HookManager.init Redwood::HOOK_DIR
## everything we need to get logging working
require "sup/buffer"
add_account accounts[:default], true
accounts.each { |k, v| add_account v, false unless k == :default }
-
- self.class.i_am_the_instance self
end
def user_accounts; @accounts.keys; end
@flash = nil
@shelled = @asking = false
@in_x = ENV["TERM"] =~ /(xterm|rxvt|screen)/
-
- self.class.i_am_the_instance self
end
def buffers; @name_map.to_a; end
@a2p[aalias] = p unless aalias.nil? || aalias.empty?
end
end
-
- self.class.i_am_the_instance self
end
def contacts; @p2a.keys end
def initialize
@mutex = Mutex.new
- self.class.i_am_the_instance self
bin = `which gpg`.chomp
-
@cmd =
case bin
when /\S/
def initialize dir
@dir = dir
@source = nil
- self.class.i_am_the_instance self
end
def self.source_name; "sup://drafts"; end
@tags = {}
Dir.mkdir dir unless File.exists? dir
-
- self.class.i_am_the_instance self
end
attr_reader :tags
def initialize dir=BASE_DIR
@dir = dir
@lock = Lockfile.new lockfile, :retries => 0, :max_age => nil
- self.class.i_am_the_instance self
end
def lockfile; File.join @dir, "lock" end
@new_labels = {}
@modified = false
labels.each { |t| @labels[t] = true }
-
- self.class.i_am_the_instance self
end
def new_label? l; @new_labels.include?(l) end
@thread = nil
@last_poll = nil
@polling = false
-
- self.class.i_am_the_instance self
end
def buffer
def initialize source_uri
@source = nil
@source_uri = source_uri
- self.class.i_am_the_instance self
Redwood::log "SentManager intialized with source uri: #@source_uri"
end
@sources = {}
@sources_dirty = false
@source_mutex = Monitor.new
- self.class.i_am_the_instance self
end
def [](id)
@fn = fn
@die = false
@thread = nil
- self.class.i_am_the_instance self
FileUtils.rm_f @fn
end
def initialize
@@actionlist = []
- self.class.i_am_the_instance self
end
def register desc, *actions, &b
def initialize
@targets = {}
- self.class.i_am_the_instance self
end
def register o; @targets[o] = true; end
end
end
-## simple singleton module. far less complete and insane than the ruby
-## standard library one, but automatically forwards methods calls and
-## allows for constructors that take arguments.
+## simple singleton module. far less complete and insane than the ruby standard
+## library one, but it automatically forwards methods calls and allows for
+## constructors that take arguments.
##
-## You must have #initialize call "self.class.i_am_the_instance self"
-## at some point or everything will fail horribly.
+## 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 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 instance defined!" unless defined? @instance
+ 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
@instance.send meth, *a, &b
end
- def i_am_the_instance o
+ def init *args
raise "there can be only one! (instance)" if defined? @instance
- @instance = o
+ @instance = new(*args)
end
end
def self.included klass
+ klass.private_class_method :allocate, :new
klass.extend ClassMethods
end
end