]> git.cworth.org Git - sup/commitdiff
console: reload
authorRich Lane <rlane@club.cc.cmu.edu>
Mon, 17 Aug 2009 06:39:14 +0000 (23:39 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Tue, 18 Aug 2009 18:00:19 +0000 (14:00 -0400)
lib/sup/modes/console-mode.rb

index c794a4c49fa4367bac4eb588b46f95a834fe7e6d..c344fa6c96de3769f914fd16f79528cfbf0f629a 100644 (file)
@@ -21,6 +21,36 @@ class Console
 
   def xapian; Index.instance.instance_variable_get :@xapian; end
   def ferret; Index.instance.instance_variable_get :@index; end
+
+  ## files that won't cause problems when reloaded
+  ## TODO expand this list / convert to blacklist
+  RELOAD_WHITELIST = %w(sup/xapian_index.rb sup/modes/console-mode.rb)
+
+  def reload
+    old_verbose = $VERBOSE
+    $VERBOSE = nil
+    old_features = $".dup
+    begin
+      fs = $".grep(/^sup\//)
+      fs.reject! { |f| not RELOAD_WHITELIST.member? f }
+      fs.each { |f| $".delete f }
+      fs.each do |f|
+        @mode << "reloading #{f}\n"
+        begin
+          require f
+        rescue LoadError => e
+          raise unless e.message =~ /no such file to load/
+        end
+      end
+    rescue Exception
+      $".clear
+      $".concat old_features
+      raise
+    ensure
+      $VERBOSE = old_verbose
+    end
+    true
+  end
 end
 
 class ConsoleMode < LogMode