Sha256: 34cdc14d63e2042e3e608cdb8de83eb68715c32561e2a349969a4a8b28c7914a

Contents?: true

Size: 555 Bytes

Versions: 1

Compression:

Stored size: 555 Bytes

Contents

module Fakeit
  module Middleware
    class Logger
      def initialize(app)
        @app = app
      end

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

      private

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fakeit-0.1.1 lib/fakeit/middleware/logger.rb