Changeset 137 for trunk/lib/camping/reloader.rb
- Timestamp:
- 07/13/2006 00:48:56 (2 years ago)
- Files:
-
- 1 modified
-
trunk/lib/camping/reloader.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/camping/reloader.rb
r134 r137 41 41 end 42 42 43 # Find the application, based on the script name. 44 def find_app(title) 45 @klass = Object.const_get(Object.constants.grep(/^#{title}$/i)[0]) rescue nil 46 end 47 48 # If the file isn't found, if we need to remove the app from the global 49 # namespace, this will be sure to do so and set @klass to nil. 50 def remove_app 51 Object.send :remove_const, @klass.name if @klass 52 @klass = nil 53 end 54 43 55 # Loads (or reloads) the application. The reloader will take care of calling 44 56 # this for you. You can certainly call it yourself if you feel it's warranted. … … 53 65 rescue Exception => e 54 66 puts "!! trouble loading #{title}: [#{e.class}] #{e.message}" 55 @klass = nil 67 find_app title 68 remove_app 56 69 return 57 70 end 58 71 59 72 @mtime = mtime 60 @klass = Object.const_get(Object.constants.grep(/^#{title}$/i)[0]) rescue nil73 find_app title 61 74 unless @klass and @klass.const_defined? :C 62 75 puts "!! trouble loading #{title}: not a Camping app, no #{title.capitalize} module found" 63 @klass = nil76 remove_app 64 77 return 65 78 end … … 74 87 ((@requires || []) + [@script]).map do |fname| 75 88 fname = fname.gsub(/^#{Regexp::quote File.dirname(@script)}\//, '') 76 File.mtime(File.join(File.dirname(@script), fname)) 89 begin 90 File.mtime(File.join(File.dirname(@script), fname)) 91 rescue Errno::ENOENT 92 remove_app 93 @mtime 94 end 77 95 end.max 78 96 end … … 87 105 end 88 106 k = @klass 89 Object. instance_eval { remove_const k.name }if k107 Object.send :remove_const, k.name if k 90 108 load_app 91 109 end
