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.
(Not documented)
# File lib/rack/reloader.rb, line 22 22: def initialize(app, cooldown = 10, backend = Stat) 23: @app = app 24: @cooldown = cooldown 25: @last = (Time.now - cooldown) 26: @cache = {} 27: @mtimes = {} 28: 29: extend backend 30: end
(Not documented)
# File lib/rack/reloader.rb, line 32 32: def call(env) 33: if @cooldown and Time.now > @last + @cooldown 34: if Thread.list.size > 1 35: Thread.exclusive{ reload! } 36: else 37: reload! 38: end 39: 40: @last = Time.now 41: end 42: 43: @app.call(env) 44: end
(Not documented)
# File lib/rack/reloader.rb, line 46 46: def reload!(stderr = $stderr) 47: rotation do |file, mtime| 48: previous_mtime = @mtimes[file] ||= mtime 49: safe_load(file, mtime, stderr) if mtime > previous_mtime 50: end 51: end
A safe Kernel::load, issuing the hooks depending on the results
# File lib/rack/reloader.rb, line 54 54: def safe_load(file, mtime, stderr = $stderr) 55: load(file) 56: stderr.puts "#{self.class}: reloaded `#{file}'" 57: file 58: rescue LoadError, SyntaxError => ex 59: stderr.puts ex 60: ensure 61: @mtimes[file] = mtime 62: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.