Show
Ignore:
Timestamp:
07/13/2006 00:48:56 (2 years ago)
Author:
why
Message:
  • lib/camping/reloader.rb: handle deletion of the script, removal of the class upon partial load.
  • lib/camping/fastcgi.rb: load new scripts.
  • bin/camping: loading of new scripts on to the index page.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/camping/reloader.rb

    r134 r137  
    4141    end 
    4242 
     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 
    4355    # Loads (or reloads) the application.  The reloader will take care of calling 
    4456    # this for you.  You can certainly call it yourself if you feel it's warranted. 
     
    5365        rescue Exception => e 
    5466            puts "!! trouble loading #{title}: [#{e.class}] #{e.message}" 
    55             @klass = nil 
     67            find_app title 
     68            remove_app 
    5669            return 
    5770        end 
    5871 
    5972        @mtime = mtime 
    60         @klass = Object.const_get(Object.constants.grep(/^#{title}$/i)[0]) rescue nil 
     73        find_app title 
    6174        unless @klass and @klass.const_defined? :C 
    6275            puts "!! trouble loading #{title}: not a Camping app, no #{title.capitalize} module found" 
    63             @klass = nil 
     76            remove_app 
    6477            return 
    6578        end 
     
    7487        ((@requires || []) + [@script]).map do |fname| 
    7588            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 
    7795        end.max 
    7896    end 
     
    87105        end 
    88106        k = @klass 
    89         Object.instance_eval { remove_const k.name } if k 
     107        Object.send :remove_const, k.name if k 
    90108        load_app 
    91109    end