Class: GrpcKit::RpcDesc

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_kit/rpc_desc.rb

Instance Method Summary collapse

Constructor Details

#initialize(name:, marshal:, unmarshal:, marshal_method:, unmarshal_method:, service_name:) ⇒ RpcDesc

Returns a new instance of RpcDesc.



26
27
28
29
30
31
32
33
# File 'lib/grpc_kit/rpc_desc.rb', line 26

def initialize(name:, marshal:, unmarshal:, marshal_method:, unmarshal_method:, service_name:)
  @name = name
  @marshal = marshal
  @unmarshal = unmarshal
  @marshal_method = marshal_method
  @unmarshal_method = unmarshal_method
  @service_name = service_name
end

Instance Method Details

#bidi_streamer?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/grpc_kit/rpc_desc.rb', line 83

def bidi_streamer?
  @marshal.is_a?(GrpcKit::GRPC::Stream) && @unmarshal.is_a?(GrpcKit::GRPC::Stream)
end

#build_client(interceptors: []) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/grpc_kit/rpc_desc.rb', line 49

def build_client(interceptors: [])
  inter = interceptors.empty? ? nil : client_interceptor.new(interceptors)

  config = GrpcKit::MethodConfig.build_for_client(
    path: path,
    ruby_style_method_name: ruby_style_name,
    protobuf: client_protobuf,
    service_name: @server_name,
    method_name: @name,
    interceptor: inter,
  )
  client.new(config)
end

#build_server(handler, interceptors: []) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/grpc_kit/rpc_desc.rb', line 35

def build_server(handler, interceptors: [])
  inter = interceptors.empty? ? nil : server_interceptor.new(interceptors)

  config = GrpcKit::MethodConfig.build_for_server(
    path: path,
    ruby_style_method_name: ruby_style_name,
    protobuf: server_protobuf,
    service_name: @server_name,
    method_name: @name,
    interceptor: inter,
  )
  server.new(handler, config)
end

#client_streamer?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/grpc_kit/rpc_desc.rb', line 75

def client_streamer?
  @marshal.is_a?(GrpcKit::GRPC::Stream) && !@unmarshal.is_a?(GrpcKit::GRPC::Stream)
end

#pathObject



67
68
69
# File 'lib/grpc_kit/rpc_desc.rb', line 67

def path
  @path ||= "/#{@service_name}/#{@name}"
end

#request_response?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/grpc_kit/rpc_desc.rb', line 71

def request_response?
  !@marshal.is_a?(GrpcKit::GRPC::Stream) && !@unmarshal.is_a?(GrpcKit::GRPC::Stream)
end

#ruby_style_nameObject



63
64
65
# File 'lib/grpc_kit/rpc_desc.rb', line 63

def ruby_style_name
  @ruby_style_name ||= to_underscore(@name).to_sym
end

#server_streamer?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/grpc_kit/rpc_desc.rb', line 79

def server_streamer?
  !@marshal.is_a?(GrpcKit::GRPC::Stream) && @unmarshal.is_a?(GrpcKit::GRPC::Stream)
end