Sha256: bc78e7cae6a9051389162276f62a51b40c03e40f01ac37f9c26d4fa69049360e

Contents?: true

Size: 1017 Bytes

Versions: 14

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

require 'grpc_kit/interceptors'
require 'grpc_kit/interceptor_registory'

module GrpcKit
  module Interceptors::Server
    class RequestResponse
      # @param interceptors [Array<GrpcKit::Grpc::ServerInterceptor>]
      def initialize(interceptors)
        @registry = GrpcKit::InterceptorRegistry.new(interceptors)
      end

      # @param request [Object] Recevied request objects
      # @param call [GrpcKit::Calls::Client::RequestResponse]
      # @yieldreturn [Object] Response object server sent
      def intercept(request, call, &block)
        do_intercept(@registry.build, request, call, &block)
      end

      private

      def do_intercept(interceptors, request, call)
        if interceptors.empty?
          return yield
        end

        interceptor = interceptors.pop
        interceptor.request_response(request: request, call: call, method: call.method) do
          do_intercept(interceptors, request, call) { yield }
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
grpc_kit-0.5.1 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.5.0 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.4.0 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.9 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.8 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.7 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.6 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.5 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.4 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.3 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.2 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.1 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.3.0 lib/grpc_kit/interceptors/server_request_response.rb
grpc_kit-0.2.1 lib/grpc_kit/interceptors/server_request_response.rb