Class: Padrino::Reloader::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/reloader.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

Constructor Details

#initialize(app, cooldown = 1) ⇒ Rack

Returns a new instance of Rack.



325
326
327
328
329
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/reloader.rb', line 325

def initialize(app, cooldown=1)
  @app = app
  @cooldown = cooldown
  @last = (Time.now - cooldown)
end

Instance Method Details

#call(env) ⇒ Object

Invoked in order to perform the reload as part of the request stack.



332
333
334
335
336
337
338
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/reloader.rb', line 332

def call(env)
  if @cooldown && Time.now > @last + @cooldown
    Thread.list.size > 1 ? Thread.exclusive { Padrino.reload! } : Padrino.reload!
    @last = Time.now
  end
  @app.call(env)
end