From: Rich Lane Date: Mon, 17 Aug 2009 06:39:14 +0000 (-0700) Subject: console: reload X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=f8ddbefdf1b53cfcb521b0f4efd3cd30fb9ef162;p=sup console: reload --- diff --git a/lib/sup/modes/console-mode.rb b/lib/sup/modes/console-mode.rb index c794a4c..c344fa6 100644 --- a/lib/sup/modes/console-mode.rb +++ b/lib/sup/modes/console-mode.rb @@ -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