Class: Padrino::Reloader::Rack
- Inherits:
-
Object
- Object
- Padrino::Reloader::Rack
- Defined in:
- lib/padrino-core/reloader/rack.rb
Overview
This class acts as a Rack middleware to be added to the application stack. This middleware performs a check and reload for source files at the start of each request, but also respects a specified cool down time during which no further action will be taken.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Invoked in order to perform the reload as part of the request stack.
-
#initialize(app, cooldown = 1) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app, cooldown = 1) ⇒ Rack
Returns a new instance of Rack.
10 11 12 13 14 15 |
# File 'lib/padrino-core/reloader/rack.rb', line 10 def initialize(app, cooldown=1) @app = app @cooldown = cooldown @last = (Time.now - cooldown) @mutex = Mutex.new end |
Instance Method Details
#call(env) ⇒ Object
Invoked in order to perform the reload as part of the request stack.
18 19 20 21 22 23 24 25 26 |
# File 'lib/padrino-core/reloader/rack.rb', line 18 def call(env) if @cooldown && Time.now > @last + @cooldown @mutex.synchronize do Padrino.reload! end @last = Time.now end @app.call(env) end |