Class: HttpDouble::RequestLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/http_double/request_logger.rb

Defined Under Namespace

Classes: HashWithIndifferentAccess, Request, Response, RoundTrip

Instance Method Summary collapse

Constructor Details

#initialize(app, log) ⇒ RequestLogger

Returns a new instance of RequestLogger.



5
6
7
8
# File 'lib/http_double/request_logger.rb', line 5

def initialize(app, log)
  @app = app
  @log = log
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/http_double/request_logger.rb', line 10

def call(env)
  @app.call(env).tap do |response|
    next if response[1].has_key? 'suppress-logging'
    @log << RoundTrip.new(
        Request.new(env),
        Response.new(
            response[0],
            HashWithIndifferentAccess.new(response[1]),
            response[2].join
        )
    )
  end
end