Sha256: 9a8ba208e6683e67f408c8677d9e2246efba0d4225153e29759d9a9a3e714d76

Contents?: true

Size: 1.18 KB

Versions: 24

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Capybara
  class Server
    class Middleware
      class Counter
        attr_reader :value

        def initialize
          @value = 0
          @mutex = Mutex.new
        end

        def increment
          @mutex.synchronize { @value += 1 }
        end

        def decrement
          @mutex.synchronize { @value -= 1 }
        end
      end

      attr_reader :error

      def initialize(app, server_errors, extra_middleware = [])
        @app = app
        @extended_app = extra_middleware.inject(@app) do |ex_app, klass|
          klass.new(ex_app)
        end
        @counter = Counter.new
        @server_errors = server_errors
      end

      def pending_requests?
        @counter.value.positive?
      end

      def clear_error
        @error = nil
      end

      def call(env)
        if env['PATH_INFO'] == '/__identify__'
          [200, {}, [@app.object_id.to_s]]
        else
          @counter.increment
          begin
            @extended_app.call(env)
          rescue *@server_errors => err
            @error ||= err
            raise err
          ensure
            @counter.decrement
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
capybara-3.15.1 lib/capybara/server/middleware.rb
capybara-3.16.2 lib/capybara/server/middleware.rb
tdiary-5.0.13 vendor/bundle/gems/capybara-3.15.0/lib/capybara/server/middleware.rb
capybara-3.16.1 lib/capybara/server/middleware.rb
tdiary-5.0.12.1 vendor/bundle/gems/capybara-3.15.0/lib/capybara/server/middleware.rb
capybara-3.16.0 lib/capybara/server/middleware.rb
capybara-3.15.0 lib/capybara/server/middleware.rb
capybara-3.14.0 lib/capybara/server/middleware.rb
capybara-3.13.2 lib/capybara/server/middleware.rb
capybara-3.13.1 lib/capybara/server/middleware.rb
capybara-3.13.0 lib/capybara/server/middleware.rb
tdiary-5.0.11 vendor/bundle/gems/capybara-3.12.0/lib/capybara/server/middleware.rb
capybara-3.12.0 lib/capybara/server/middleware.rb
capybara-3.11.1 lib/capybara/server/middleware.rb
capybara-3.11.0 lib/capybara/server/middleware.rb
capybara-3.10.1 lib/capybara/server/middleware.rb
capybara-3.10.0 lib/capybara/server/middleware.rb
capybara-3.9.0 lib/capybara/server/middleware.rb
capybara-3.8.2 lib/capybara/server/middleware.rb
capybara-3.8.1 lib/capybara/server/middleware.rb