Class: Yrpc::Controllers::Request

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

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

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 = 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)
  method_message = *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
    message = method_message
    raise Yrpc::Error::ResponseError.new(code, message)
  else
    super
  end
end

Instance Attribute Details

#active_callObject (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

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/yrpc/controllers/request.rb', line 6

def message
  @message
end

#method_keyObject (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

#serviceObject (readonly)

Returns the value of attribute service.



14
15
16
# File 'lib/yrpc/controllers/request.rb', line 14

def service
  @service
end

#typeObject (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

#messagesObject

返回这个request的所有mesage 要根据stremer类型来判断



80
81
82
83
84
85
86
87
88
# File 'lib/yrpc/controllers/request.rb', line 80

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

#method_nameObject

grpc 中的 service.method



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

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

#request_classObject



70
71
72
# File 'lib/yrpc/controllers/request.rb', line 70

def request_class
  @rpc_desc.input
end

#response_classObject



65
66
67
# File 'lib/yrpc/controllers/request.rb', line 65

def response_class
  @rpc_desc.output
end

#service_keyObject



48
49
50
# File 'lib/yrpc/controllers/request.rb', line 48

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