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.



10
11
12
13
14
15
16
17
# File 'lib/grpc_kit/rpc_desc.rb', line 10

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)


65
66
67
# File 'lib/grpc_kit/rpc_desc.rb', line 65

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

#build_clientObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/grpc_kit/rpc_desc.rb', line 33

def build_client
  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: client_interceptor.new,
  )
  client.new(config)
end

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



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/grpc_kit/rpc_desc.rb', line 19

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)


57
58
59
# File 'lib/grpc_kit/rpc_desc.rb', line 57

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

#pathObject



49
50
51
# File 'lib/grpc_kit/rpc_desc.rb', line 49

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

#request_response?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/grpc_kit/rpc_desc.rb', line 53

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

#ruby_style_nameObject



45
46
47
# File 'lib/grpc_kit/rpc_desc.rb', line 45

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

#server_streamer?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/grpc_kit/rpc_desc.rb', line 61

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