Sha256: 8c8485c32bba1b9fd4333664694dedea164eb7d7e2ca13a41b7e1f673e751beb

Contents?: true

Size: 805 Bytes

Versions: 18

Compression:

Stored size: 805 Bytes

Contents

module Padrino
  module Reloader
    ##
    # 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.
    #
    class Rack
      def initialize(app, cooldown=1)
        @app = app
        @cooldown = cooldown
        @last = (Time.now - cooldown)
      end

      # Invoked in order to perform the reload as part of the request stack.
      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
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
padrino-core-0.12.8.1 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.8 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.7 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.6 lib/padrino-core/reloader/rack.rb
padrino-core-0.13.1.beta1 lib/padrino-core/reloader/rack.rb
padrino-core-0.13.0 lib/padrino-core/reloader/rack.rb
padrino-core-0.13.0.beta3 lib/padrino-core/reloader/rack.rb
padrino-core-0.13.0.beta2 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.5 lib/padrino-core/reloader/rack.rb
padrino-core-0.13.0.beta1 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.4 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.3 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.2 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.1 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.0 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.0.rc3 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.0.rc2 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.0.rc1 lib/padrino-core/reloader/rack.rb