Class: Reins::ReloadMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/reins/reload_middleware.rb

Overview

Polls registered autoload paths for mtime changes; on a change, asks Reins::Autoloader to reload before passing the request through.

Mounted automatically when Reins.config.reload_classes is true.

Instance Method Summary collapse

Constructor Details

#initialize(app, paths) ⇒ ReloadMiddleware

Returns a new instance of ReloadMiddleware.



7
8
9
10
11
# File 'lib/reins/reload_middleware.rb', line 7

def initialize(app, paths)
  @app = app
  @paths = paths
  @last_check = newest_mtime
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/reins/reload_middleware.rb', line 13

def call(env)
  current = newest_mtime
  if current && @last_check && current > @last_check
    Reins::Autoloader.reload!
    @last_check = current
  end
  @app.call(env)
end