Class: Gapic::Presenters::MethodPresenter
Overview
A presenter for rpc methods.
Instance Method Summary
collapse
#fix_namespace, #ruby_namespace, #ruby_namespace_for_address
Constructor Details
Returns a new instance of MethodPresenter.
29
30
31
32
|
# File 'lib/gapic/presenters/method_presenter.rb', line 29
def initialize api, method
@api = api
@method = method
end
|
Instance Method Details
#arguments ⇒ Object
73
74
75
76
|
# File 'lib/gapic/presenters/method_presenter.rb', line 73
def arguments
arguments = @method.input.fields.reject(&:output_only?)
arguments.map { |arg| FieldPresenter.new @api, @method.input, arg }
end
|
#client_streaming? ⇒ Boolean
153
154
155
|
# File 'lib/gapic/presenters/method_presenter.rb', line 153
def client_streaming?
@method.client_streaming
end
|
#doc_description ⇒ Object
56
57
58
|
# File 'lib/gapic/presenters/method_presenter.rb', line 56
def doc_description
@method.
end
|
#doc_response_type ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/gapic/presenters/method_presenter.rb', line 60
def doc_response_type
ret = return_type
ret = "Gapic::Operation" if lro?
if server_streaming?
ret = "Enumerable<#{ret}>"
elsif paged?
paged_type = paged_response_type
paged_type = "Gapic::Operation" if paged_type == "Google::Longrunning::Operation"
ret = "Gapic::PagedEnumerable<#{paged_type}>"
end
ret
end
|
#fields ⇒ Object
78
79
80
|
# File 'lib/gapic/presenters/method_presenter.rb', line 78
def fields
@method.input.fields.map { |field| FieldPresenter.new @api, @method.input, field }
end
|
#fields_with_first_oneof ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/gapic/presenters/method_presenter.rb', line 82
def fields_with_first_oneof
return fields if @method.input.oneof_decl.empty?
selected_fields = []
have_oneof = []
@method.input.fields.each do |field|
idx = field.oneof_index
selected_fields << field unless have_oneof.include? idx
have_oneof << idx
end
selected_fields.map { |field| FieldPresenter.new @api, @method.input, field }
end
|
#grpc_method_name ⇒ Object
205
206
207
|
# File 'lib/gapic/presenters/method_presenter.rb', line 205
def grpc_method_name
@method.name
end
|
#grpc_service_config ⇒ Object
198
199
200
201
202
203
|
# File 'lib/gapic/presenters/method_presenter.rb', line 198
def grpc_service_config
if @api.grpc_service_config&.service_method_level_configs&.key?(service.grpc_full_name) &&
@api.grpc_service_config.service_method_level_configs[service.grpc_full_name]&.key?(grpc_method_name)
@api.grpc_service_config.service_method_level_configs[service.grpc_full_name][grpc_method_name]
end
end
|
#kind ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/gapic/presenters/method_presenter.rb', line 42
def kind
if client_streaming?
if server_streaming?
:bidi
else
:client
end
elsif server_streaming?
:server
else
:normal
end
end
|
#lro? ⇒ Boolean
147
148
149
150
151
|
# File 'lib/gapic/presenters/method_presenter.rb', line 147
def lro?
return paged_response_type == "Google::Longrunning::Operation" if paged?
message_ruby_type(@method.output) == "Google::Longrunning::Operation"
end
|
#name ⇒ Object
38
39
40
|
# File 'lib/gapic/presenters/method_presenter.rb', line 38
def name
ActiveSupport::Inflector.underscore @method.name
end
|
#paged? ⇒ Boolean
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/gapic/presenters/method_presenter.rb', line 161
def paged?
return false if server_streaming?
address = @method.address.join "."
return false if address == "google.cloud.talent.v4beta1.SearchProfiles"
return false if address == "google.cloud.talent.v4beta1.SearchJobs"
paged_request?(@method.input) && paged_response?(@method.output)
end
|
#paged_response_type ⇒ Object
175
176
177
178
179
180
181
182
183
|
# File 'lib/gapic/presenters/method_presenter.rb', line 175
def paged_response_type
return nil unless paged_response? @method.output
repeated_field = @method.output.fields.find do |f|
f.label == Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED &&
f.type == Google::Protobuf::FieldDescriptorProto::Type::TYPE_MESSAGE
end
message_ruby_type repeated_field.message
end
|
#request_type ⇒ Object
97
98
99
|
# File 'lib/gapic/presenters/method_presenter.rb', line 97
def request_type
message_ruby_type @method.input
end
|
#return_type ⇒ Object
101
102
103
|
# File 'lib/gapic/presenters/method_presenter.rb', line 101
def return_type
message_ruby_type @method.output
end
|
#routing_params ⇒ Array<String>
Returns The segment key names.
#routing_params? ⇒ Boolean
194
195
196
|
# File 'lib/gapic/presenters/method_presenter.rb', line 194
def routing_params?
routing_params.any?
end
|
#samples ⇒ Object
speech_transcribe_sync_gcs.yaml
139
140
141
142
143
144
145
|
# File 'lib/gapic/presenters/method_presenter.rb', line 139
def samples
sample_configs = @api.incode_samples.select do |sample_config|
sample_config["service"] == @method.address[0...-1].join(".") &&
sample_config["rpc"] == @method.name
end
sample_configs.map { |sample_config| SamplePresenter.new @api, sample_config }
end
|
#server_streaming? ⇒ Boolean
157
158
159
|
# File 'lib/gapic/presenters/method_presenter.rb', line 157
def server_streaming?
@method.server_streaming
end
|
#service ⇒ Object
34
35
36
|
# File 'lib/gapic/presenters/method_presenter.rb', line 34
def service
ServicePresenter.new @api, @method.parent
end
|
#yield_doc_description ⇒ Object
110
111
112
113
114
|
# File 'lib/gapic/presenters/method_presenter.rb', line 110
def yield_doc_description
return "Register a callback to be run when an operation is done." if lro?
"Access the result along with the RPC operation"
end
|
#yield_params ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/gapic/presenters/method_presenter.rb', line 116
def yield_params
if lro?
return [
OpenStruct.new(
name: "operation",
doc_types: "Gapic::Operation"
)
]
end
[
OpenStruct.new(
name: "result",
doc_types: return_type
),
OpenStruct.new(
name: "operation",
doc_types: "GRPC::ActiveCall::Operation"
)
]
end
|
#yields? ⇒ Boolean
105
106
107
108
|
# File 'lib/gapic/presenters/method_presenter.rb', line 105
def yields?
!server_streaming?
end
|