Sha256: cf429536b200dfd2271543708931897fafc11b1f7e4622ed924b765627e56480

Contents?: true

Size: 818 Bytes

Versions: 24

Compression:

Stored size: 818 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)
        @mutex = Mutex.new
      end

      # Invoked in order to perform the reload as part of the request stack.
      def call(env)
        if @cooldown && Time.now > @last + @cooldown
          @mutex.synchronize do
            Padrino.reload!
          end
          @last = Time.now
        end
        @app.call(env)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
padrino-core-0.16.0.pre3 lib/padrino-core/reloader/rack.rb
padrino-core-0.16.0.pre2 lib/padrino-core/reloader/rack.rb
padrino-core-0.15.3 lib/padrino-core/reloader/rack.rb
padrino-core-0.15.2 lib/padrino-core/reloader/rack.rb
padrino-core-0.15.1 lib/padrino-core/reloader/rack.rb
padrino-core-0.15.0 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.4 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.3 lib/padrino-core/reloader/rack.rb
padrino-core-0.12.9 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.2 lib/padrino-core/reloader/rack.rb
padrino-core-0.13.3.4 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.1.1 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.1 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.0.2 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.0.1 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.0 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.0.rc2 lib/padrino-core/reloader/rack.rb
padrino-core-0.14.0.rc1 lib/padrino-core/reloader/rack.rb
padrino-core-0.13.3.3 lib/padrino-core/reloader/rack.rb
padrino-core-0.13.3.2 lib/padrino-core/reloader/rack.rb