Sha256: 20665dfb013e4bd49b3bf8762ca008c2385c2b3446d7805e4585e92a14d84bc9

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

require 'protobuf/logging'

module Protobuf
  module Rpc
    class ServiceDispatcher
      include ::Protobuf::Logging

      attr_reader :env

      def initialize(_app)
        # End of the line...
      end

      def call(env)
        dup._call(env)
      end

      def _call(env)
        @env = env

        env.response = dispatch_rpc_request
        env
      end

      def rpc_service
        @rpc_service ||= env.rpc_service.new(env)
      end

      private

      # Call the given service method.
      def dispatch_rpc_request
        rpc_service.call(method_name)
        rpc_service.response
      rescue NoMethodError
        raise MethodNotFound, "#{service_name}##{method_name} is not a defined RPC method."
      end

      def method_name
        env.method_name
      end

      def service_name
        env.service_name
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
protobuf-3.6.11 lib/protobuf/rpc/service_dispatcher.rb