High performant source reloader
This class acts as Rack middleware.
What makes it especially suited for use in a production environment is that any file will only be checked once and there will only be made one system call stat(2).
Please note that this will not reload files in the background, it does so only when actively called.
It is performing a check/reload cycle at the start of every request, but also respects a cool down time, during which nothing will be done.
# File lib/rack/reloader.rb, line 33 33: def call(env) 34: if @cooldown and Time.now > @last + @cooldown 35: if Thread.list.size > 1 36: Thread.exclusive{ reload! } 37: else 38: reload! 39: end 40: 41: @last = Time.now 42: end 43: 44: @app.call(env) 45: end
# File lib/rack/reloader.rb, line 47 47: def reload!(stderr = $stderr) 48: rotation do |file, mtime| 49: previous_mtime = @mtimes[file] ||= mtime 50: safe_load(file, mtime, stderr) if mtime > previous_mtime 51: end 52: end
A safe Kernel::load, issuing the hooks depending on the results
# File lib/rack/reloader.rb, line 55 55: def safe_load(file, mtime, stderr = $stderr) 56: load(file) 57: stderr.puts "#{self.class}: reloaded `#{file}'" 58: file 59: rescue LoadError, SyntaxError => ex 60: stderr.puts ex 61: ensure 62: @mtimes[file] = mtime 63: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.