module Spinebox # Rack middleware that reloads the sprockets environment on # every request with a default delay of 5 seconds class Reloader def initialize(app, cooldown = 5) @app, @cooldown = app, cooldown @last = (Time.now - cooldown) end def call(env) reload! if Time.now > @last + @cooldown @app.call(env) end private def reload! Spinebox.config.assets.version = '0.1' Spinebox.config.views.version = '0.1' @last = Time.now end end end