Parent

Namespace

Class Index [+]

Quicksearch

Rack::Reloader

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.

Public Class Methods

new(app, cooldown = 10, backend = Stat) click to toggle source

(Not documented)

    # File lib/rack/reloader.rb, line 23
23:     def initialize(app, cooldown = 10, backend = Stat)
24:       @app = app
25:       @cooldown = cooldown
26:       @last = (Time.now - cooldown)
27:       @cache = {}
28:       @mtimes = {}
29: 
30:       extend backend
31:     end

Public Instance Methods

call(env) click to toggle source

(Not documented)

    # 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
reload!(stderr = $stderr) click to toggle source

(Not documented)

    # 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
safe_load(file, mtime, stderr = $stderr) click to toggle source

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.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.