class Fakeit::Middleware::Recorder

Public Class Methods

new(app) click to toggle source
# File lib/fakeit/middleware/recorder.rb, line 4
    def initialize(app) = @app = app

    def call(env)
      env
        .tap(&method(:log_request))
        .then { @app.call(_1) }
        .tap(&method(:log_response))
    end

    private

    def log_request(env)
      env['rack.input']
        &.tap { |body| Logger.info("Request body: #{body.read}") }
        &.tap { |body| body.rewind }
    end

    def log_response(response) = Logger.info("Response body: #{response[2].first}")
  end
end

Public Instance Methods

call(env) click to toggle source
# File lib/fakeit/middleware/recorder.rb, line 6
def call(env)
  env
    .tap(&method(:log_request))
    .then { @app.call(_1) }
    .tap(&method(:log_response))
end
log_request(env) click to toggle source
# File lib/fakeit/middleware/recorder.rb, line 15
def log_request(env)
  env['rack.input']
    &.tap { |body| Logger.info("Request body: #{body.read}") }
    &.tap { |body| body.rewind }
end
log_response(response) click to toggle source
# File lib/fakeit/middleware/recorder.rb, line 21
  def log_response(response) = Logger.info("Response body: #{response[2].first}")
end