Sha256: 98512ec02d39631b98910381f381e160cf9d91c31cc3f9f1536123cc28dc12d9

Contents?: true

Size: 573 Bytes

Versions: 11

Compression:

Stored size: 573 Bytes

Contents

module Fakeit
  module Middleware
    class Recorder
      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| Logger.info("Request body: #{body.read}") }
          &.tap { |body| body.rewind }
      end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fakeit-0.4.2 lib/fakeit/middleware/recorder.rb
fakeit-0.4.1 lib/fakeit/middleware/recorder.rb
fakeit-0.4.0 lib/fakeit/middleware/recorder.rb
fakeit-0.3.1 lib/fakeit/middleware/recorder.rb
fakeit-0.3.0 lib/fakeit/middleware/recorder.rb
fakeit-0.2.1 lib/fakeit/middleware/recorder.rb
fakeit-0.2.0 lib/fakeit/middleware/recorder.rb
fakeit-0.1.5 lib/fakeit/middleware/recorder.rb
fakeit-0.1.4 lib/fakeit/middleware/recorder.rb
fakeit-0.1.3 lib/fakeit/middleware/recorder.rb
fakeit-0.1.2 lib/fakeit/middleware/recorder.rb