Class: Capybara::Server::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/server.rb

Defined Under Namespace

Classes: Counter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, server_errors) ⇒ Middleware

Returns a new instance of Middleware



29
30
31
32
33
# File 'lib/capybara/server.rb', line 29

def initialize(app, server_errors)
  @app = app
  @counter = Counter.new
  @server_errors = server_errors
end

Instance Attribute Details

#errorObject

Returns the value of attribute error



27
28
29
# File 'lib/capybara/server.rb', line 27

def error
  @error
end

Instance Method Details

#call(env) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/capybara/server.rb', line 39

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

#pending_requests?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/capybara/server.rb', line 35

def pending_requests?
  @counter.value > 0
end