X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Futil.rb;h=aa3ee764ac59b276d7f4ae758d4b119e141832c2;hb=3de96fb9b308afe600c7ccfcee75913f039ef4f6;hp=adf44b7ccbd2b46f056a47fdf04dfa9a650275c5;hpb=d3e1ccd43bbd1b6c4076dfe110deede57e1b1bab;p=sup diff --git a/lib/sup/util.rb b/lib/sup/util.rb index adf44b7..aa3ee76 100644 --- a/lib/sup/util.rb +++ b/lib/sup/util.rb @@ -25,6 +25,7 @@ class Lockfile def lockinfo_on_disk h = load_lock_id IO.read(path) h['mtime'] = File.mtime path + h['path'] = path h end @@ -495,19 +496,20 @@ class Time 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 @@ -517,13 +519,14 @@ module Singleton @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 @@ -651,7 +654,7 @@ class Iconv begin Iconv.iconv(target + "//IGNORE", charset, text + " ").join[0 .. -2] rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::InvalidCharacter, Iconv::IllegalSequence => e - Redwood::log "warning: error (#{e.class.name}) decoding text from #{charset} to #{target}: #{text[0 ... 20]}" + info "couldn't transcode text from #{charset} to #{target} (\"#{text[0 ... 20]}\"...)" text end end