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



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

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.



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

def active_call
  @active_call
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#method_keyObject (readonly)

Returns the value of attribute method_key.



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

def method_key
  @method_key
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#messagesObject

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



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

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



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

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)


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

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