Class: Gruf::Controllers::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/gruf/controllers/request.rb

Overview

Encapsulates a request for a controller

Defined Under Namespace

Classes: Type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_key:, service:, rpc_desc:, active_call:, message:) ⇒ Request

Returns a new instance of Request.

Parameters:

  • method_key (Symbol)

    The method symbol of the RPC method being executed

  • service (Class)

    The class of the service being executed against

  • rpc_desc (GRPC::RpcDesc)

    The RPC descriptor of the call

  • active_call (GRPC::ActiveCall)

    The restricted view of the call

  • message (Object)

    The protobuf message (or messages) of the request



53
54
55
56
57
58
59
# File 'lib/gruf/controllers/request.rb', line 53

def initialize(method_key:, service:, rpc_desc:, active_call:, message:)
  @method_key = method_key
  @service = service
  @active_call = active_call
  @message = message
  @type = Type.new(rpc_desc)
end

Instance Attribute Details

#active_callObject (readonly)

Returns the value of attribute active_call.



26
27
28
# File 'lib/gruf/controllers/request.rb', line 26

def active_call
  @active_call
end

#messageObject (readonly)

Returns the value of attribute message.



24
25
26
# File 'lib/gruf/controllers/request.rb', line 24

def message
  @message
end

#method_keyObject (readonly)

Returns the value of attribute method_key.



28
29
30
# File 'lib/gruf/controllers/request.rb', line 28

def method_key
  @method_key
end

#typeObject (readonly)

Returns the value of attribute type.



30
31
32
# File 'lib/gruf/controllers/request.rb', line 30

def type
  @type
end

Instance Method Details

#messagesObject

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



85
86
87
88
89
90
91
92
93
# File 'lib/gruf/controllers/request.rb', line 85

def messages
  if client_streamer?
    message.call { |msg| yield msg }
  elsif bidi_streamer?
    message
  else
    [message]
  end
end

#method_nameString

Parse the method signature into a service.method name format

Returns:

  • (String)

    The parsed service method name



76
77
78
# File 'lib/gruf/controllers/request.rb', line 76

def method_name
  "#{service_key}.#{method_key}"
end

#service_keyString

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

Returns:

  • (String)


67
68
69
# File 'lib/gruf/controllers/request.rb', line 67

def service_key
  @service.name.underscore.tr('/', '.').gsub('.service', '')
end