Class: Yrpc::Controllers::Request
- Inherits:
-
Object
- Object
- Yrpc::Controllers::Request
- Defined in:
- lib/yrpc/controllers/request.rb
Defined Under Namespace
Classes: Type
Instance Attribute Summary collapse
-
#active_call ⇒ Object
readonly
Returns the value of attribute active_call.
-
#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
struct GRPC::RpcDesc.
-
#messages ⇒ Object
返回这个request的所有mesage 要根据stremer类型来判断.
- #method_missing(method_id, *arguments, &block) ⇒ Object
-
#method_name ⇒ Object
grpc 中的 service.method.
- #request_class ⇒ Object
- #response_class ⇒ Object
- #service_key ⇒ Object
Constructor Details
#initialize(method_key:, service:, rpc_desc:, active_call:, message:) ⇒ Request
struct GRPC::RpcDesc
38 39 40 41 42 43 44 45 |
# File 'lib/yrpc/controllers/request.rb', line 38 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) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/yrpc/controllers/request.rb', line 52 def method_missing(method_id, *arguments, &block) = *arguments.join if (method_id.to_s =~ /^raise_[\w]+/) == 0 error_type = method_id.to_s.split('raise_')[1].upcase! code = "Yrpc::Response::Code::#{error_type}".constantize = raise Yrpc::Error::ResponseError.new(code, ) else super end end |
Instance Attribute Details
#active_call ⇒ Object (readonly)
Returns the value of attribute active_call.
8 9 10 |
# File 'lib/yrpc/controllers/request.rb', line 8 def active_call @active_call end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/yrpc/controllers/request.rb', line 6 def @message end |
#method_key ⇒ Object (readonly)
Returns the value of attribute method_key.
10 11 12 |
# File 'lib/yrpc/controllers/request.rb', line 10 def method_key @method_key end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
14 15 16 |
# File 'lib/yrpc/controllers/request.rb', line 14 def service @service end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/yrpc/controllers/request.rb', line 12 def type @type end |
Instance Method Details
#messages ⇒ Object
返回这个request的所有mesage 要根据stremer类型来判断
80 81 82 83 84 85 86 87 88 |
# File 'lib/yrpc/controllers/request.rb', line 80 def if client_streamer? .call { |msg| yield msg } elsif bidi_streamer? else [] end end |
#method_name ⇒ Object
grpc 中的 service.method
75 76 77 |
# File 'lib/yrpc/controllers/request.rb', line 75 def method_name "#{service_key}.#{method_key}" end |
#request_class ⇒ Object
70 71 72 |
# File 'lib/yrpc/controllers/request.rb', line 70 def request_class @rpc_desc.input end |
#response_class ⇒ Object
65 66 67 |
# File 'lib/yrpc/controllers/request.rb', line 65 def response_class @rpc_desc.output end |
#service_key ⇒ Object
48 49 50 |
# File 'lib/yrpc/controllers/request.rb', line 48 def service_key @service.name.underscore.tr('/', '.').gsub('.service', '') end |