class Gruf::Controllers::Request

Encapsulates a request for a controller

Attributes

active_call[R]

@var [GRPC::ActiveCall] active_call

message[R]

@var [Object] message

method_key[R]

@var [Symbol] method_key

service[R]

@var [Class] service

type[R]

@var [Gruf::Controllers::Request::Type] type

Public Class Methods

new(method_key:, service:, rpc_desc:, active_call:, message:) click to toggle source

Initialize an inbound controller request object

@param [Symbol] method_key The method symbol of the RPC method being executed @param [Class] service The class of the service being executed against @param [GRPC::RpcDesc] rpc_desc The RPC descriptor of the call @param [GRPC::ActiveCall] active_call The restricted view of the call @param [Object|Google::Protobuf::MessageExts] message The protobuf message (or messages) of the request

# File lib/gruf/controllers/request.rb, line 63
def initialize(method_key:, service:, rpc_desc:, active_call:, message:)
  @method_key = method_key
  @service = service
  @active_call = active_call
  @message = message
  @rpc_desc = rpc_desc
  @type = Type.new(rpc_desc)
end

Public Instance Methods

messages() { |msg| ... } click to toggle source

Return all messages for this request, properly handling different request types

@return [Enumerable<Object>] All messages for this request

# File lib/gruf/controllers/request.rb, line 110
def messages
  if client_streamer?
    # rubocop:disable Style/ExplicitBlockArgument
    @message.call { |msg| yield msg }
    # rubocop:enable Style/ExplicitBlockArgument
  elsif bidi_streamer?
    @message
  else
    [@message]
  end
end
method_name() click to toggle source

Parse the method signature into a service.method name format

@return [String] The parsed service method name

# File lib/gruf/controllers/request.rb, line 101
def method_name
  "#{service_key}.#{@method_key}"
end
request_class() click to toggle source

@return [Class] The class of the request message

# File lib/gruf/controllers/request.rb, line 92
def request_class
  @rpc_desc.input
end
response_class() click to toggle source

@return [Class] The class of the response message

# File lib/gruf/controllers/request.rb, line 85
def response_class
  @rpc_desc.output
end
service_key() click to toggle source

Returns the service name as a translated name separated by periods. Strips the superfluous “Service” suffix from the name

@return [String] The mapped service key

# File lib/gruf/controllers/request.rb, line 78
def service_key
  @service.name.underscore.tr('/', '.').gsub('.service', '')
end