Class: ProtoPlugin::MethodDescriptor

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Commentable
Defined in:
lib/proto_plugin/method_descriptor.rb

Overview

A wrapper class around Google::Protobuf::MethodDescriptorProto which provides helpers and more idiomatic Ruby access patterns.

Any method not defined directly is delegated to the descriptor the wrapper was initialized with.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commentable

#comments, #leading_comments, #source_location, #trailing_comments

Constructor Details

#initialize(descriptor, service, context) ⇒ MethodDescriptor

Returns a new instance of MethodDescriptor.

Parameters:

  • descriptor (Google::Protobuf::MethodDescriptorProto)
  • service (ServiceDescriptor)

    The service this method was defined in.

  • context (Context)


26
27
28
29
30
31
# File 'lib/proto_plugin/method_descriptor.rb', line 26

def initialize(descriptor, service, context)
  super(descriptor)
  @descriptor = descriptor
  @service = service
  @context = context
end

Instance Attribute Details

#descriptorGoogle::Protobuf::MethodDescriptorProto (readonly)

Returns:

  • (Google::Protobuf::MethodDescriptorProto)


16
17
18
# File 'lib/proto_plugin/method_descriptor.rb', line 16

def descriptor
  @descriptor
end

#serviceServiceDescriptor (readonly)

The service this method was defined in.

Returns:



21
22
23
# File 'lib/proto_plugin/method_descriptor.rb', line 21

def service
  @service
end

Instance Method Details

#bidirectional_streaming?Boolean

Returns true if both the client and server may send multiple streamed messages.

Returns:

  • (Boolean)


78
79
80
# File 'lib/proto_plugin/method_descriptor.rb', line 78

def bidirectional_streaming?
  client_streaming? && server_streaming?
end

#client_streaming?Boolean

Returns true if the client may stream multiple client messages.

Returns:

  • (Boolean)


57
58
59
# File 'lib/proto_plugin/method_descriptor.rb', line 57

def client_streaming?
  descriptor.client_streaming
end

#fileFileDescriptor

The file descriptor this method belongs to.

Returns:



36
37
38
# File 'lib/proto_plugin/method_descriptor.rb', line 36

def file
  service.file
end

#inputMessageDescriptor

Returns the MessageDescriptor of the method’s input type.

Returns:



43
44
45
# File 'lib/proto_plugin/method_descriptor.rb', line 43

def input
  @context.type_by_proto_name(input_type)
end

#outputMessageDescriptor

Returns the MessageDescriptor of the method’s output type.

Returns:



50
51
52
# File 'lib/proto_plugin/method_descriptor.rb', line 50

def output
  @context.type_by_proto_name(output_type)
end

#server_streaming?Boolean

Returns true if the server may stream multiple server messages.

Returns:

  • (Boolean)


64
65
66
# File 'lib/proto_plugin/method_descriptor.rb', line 64

def server_streaming?
  descriptor.server_streaming
end

#unary?Boolean

Returns true if both the client and server only may send single messages.

Returns:

  • (Boolean)


71
72
73
# File 'lib/proto_plugin/method_descriptor.rb', line 71

def unary?
  !client_streaming? && !server_streaming?
end