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

Parameters:

  • name (Symbol)

    path name

  • marshal (Class, GrpcKit::GRPC::Stream)

    marshaling object

  • unmarshal (Class, GrpcKit::GRPC::Stream)

    unmarshaling object

  • marshal_method (Symbol)

    method name of marshaling which marshal is called this method

  • unmarshal_method (Symbol)

    method name of unmarshaling which unmarshal is called this method

  • service_name (String)

32
33
34
35
36
37
38
39
# File 'lib/grpc_kit/rpc_desc.rb', line 32

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)

100
101
102
# File 'lib/grpc_kit/rpc_desc.rb', line 100

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

#build_client(interceptors: []) ⇒ #invoke

Returns Client version of rpc class

Parameters:

Returns:

  • (#invoke)

    Client version of rpc class


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/grpc_kit/rpc_desc.rb', line 60

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: @service_name,
    method_name: @name,
    interceptor: inter,
  )
  client.new(config)
end

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

Returns Server version of rpc class

Parameters:

Returns:

  • (#invoke)

    Server version of rpc class


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/grpc_kit/rpc_desc.rb', line 44

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: @service_name,
    method_name: @name,
    interceptor: inter,
  )
  server.new(handler, config)
end

#client_streamer?Boolean

Returns:

  • (Boolean)

90
91
92
# File 'lib/grpc_kit/rpc_desc.rb', line 90

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

#pathString

Returns Full name of path name

Returns:

  • (String)

    Full name of path name


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

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

#request_response?Boolean

Returns:

  • (Boolean)

85
86
87
# File 'lib/grpc_kit/rpc_desc.rb', line 85

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

#ruby_style_nameSymbol

Returns Snake case name

Returns:

  • (Symbol)

    Snake case name


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

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

#server_streamer?Boolean

Returns:

  • (Boolean)

95
96
97
# File 'lib/grpc_kit/rpc_desc.rb', line 95

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