Class: Gruf::Controllers::Request
- Inherits:
-
Object
- Object
- Gruf::Controllers::Request
- Defined in:
- lib/gruf/controllers/request.rb
Overview
Encapsulates a request for a controller
Defined Under Namespace
Classes: Type
Instance Attribute Summary collapse
-
#active_call ⇒ Object
readonly
Returns the value of attribute active_call.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#method_key ⇒ Object
readonly
Returns the value of attribute method_key.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(method_key:, service:, rpc_desc:, active_call:, message:) ⇒ Request
constructor
Initialize an inbound controller request object.
-
#messages ⇒ Enumerable<Object>, Object
Return all messages for this request, properly handling different request types.
-
#method_name ⇒ String
Parse the method signature into a service.method name format.
-
#request_class ⇒ Class
The class of the request message.
-
#response_class ⇒ Class
The class of the response message.
-
#service_key ⇒ String
Returns the service name as a translated name separated by periods.
Constructor Details
#initialize(method_key:, service:, rpc_desc:, active_call:, message:) ⇒ Request
Initialize an inbound controller request object
73 74 75 76 77 78 79 80 81 |
# File 'lib/gruf/controllers/request.rb', line 73 def initialize(method_key:, service:, rpc_desc:, active_call:, message:) @method_key = method_key @service = service @active_call = active_call @message = @rpc_desc = rpc_desc @type = Type.new(rpc_desc) @context = ::ActiveSupport::HashWithIndifferentAccess.new end |
Instance Attribute Details
#active_call ⇒ Object (readonly)
Returns the value of attribute active_call.
29 30 31 |
# File 'lib/gruf/controllers/request.rb', line 29 def active_call @active_call end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
43 44 45 |
# File 'lib/gruf/controllers/request.rb', line 43 def context @context end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
26 27 28 |
# File 'lib/gruf/controllers/request.rb', line 26 def @message end |
#method_key ⇒ Object (readonly)
Returns the value of attribute method_key.
32 33 34 |
# File 'lib/gruf/controllers/request.rb', line 32 def method_key @method_key end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
38 39 40 |
# File 'lib/gruf/controllers/request.rb', line 38 def service @service end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
35 36 37 |
# File 'lib/gruf/controllers/request.rb', line 35 def type @type end |
Instance Method Details
#messages ⇒ Enumerable<Object>, Object
Return all messages for this request, properly handling different request types
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gruf/controllers/request.rb', line 122 def 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 ⇒ String
Parse the method signature into a service.method name format
112 113 114 |
# File 'lib/gruf/controllers/request.rb', line 112 def method_name "#{service_key}.#{@method_key}" end |
#request_class ⇒ Class
Returns The class of the request message.
103 104 105 |
# File 'lib/gruf/controllers/request.rb', line 103 def request_class @rpc_desc.input end |
#response_class ⇒ Class
Returns The class of the response message.
96 97 98 |
# File 'lib/gruf/controllers/request.rb', line 96 def response_class @rpc_desc.output end |
#service_key ⇒ String
Returns the service name as a translated name separated by periods. Strips the superfluous “Service” suffix from the name
89 90 91 |
# File 'lib/gruf/controllers/request.rb', line 89 def service_key @service.name.to_s.underscore.tr('/', '.').gsub('.service', '') end |