Class: Spinebox::Reloader

Inherits:
Object
  • Object
show all
Defined in:
lib/spinebox/reloader.rb

Overview

Rack middleware that reloads the sprockets environment on every request with a default delay of 5 seconds

Instance Method Summary collapse

Constructor Details

#initialize(app, cooldown = 5) ⇒ Reloader

Returns a new instance of Reloader.



7
8
9
10
# File 'lib/spinebox/reloader.rb', line 7

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

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
# File 'lib/spinebox/reloader.rb', line 12

def call(env)
  reload! if Time.now > @last + @cooldown
  @app.call(env)
end