Class: Gapic::Presenters::MethodPresenter
Overview
A presenter for rpc methods.
Defined Under Namespace
Classes: YieldParams
Instance Attribute Summary collapse
Instance Method Summary
collapse
#ensure_absolute_namespace, #fix_namespace, #ruby_namespace, #ruby_namespace_for_address
Constructor Details
#initialize(service_presenter, api, method) ⇒ MethodPresenter
Returns a new instance of MethodPresenter.
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/gapic/presenters/method_presenter.rb', line 55
def initialize service_presenter, api, method
@service_presenter = service_presenter
@api = api
@method = method
@type = "method"
is_lro = @service_presenter.address.join(".") == Gapic::Model::Mixins::LRO_SERVICE
service_config_override_http = is_lro ? @api.service_config : nil
@http = Gapic::Model::Method::HttpAnnotation.create_with_override @method, service_config_override_http
@http_bindings = @http.bindings.map { |binding| Gapic::Presenters::Method::HttpBindingPresenter.new binding }
@routing = Gapic::Model::Method::Routing.new @method.routing, @http
@lro = Gapic::Model::Method.parse_lro @method, @api
@rest = MethodRestPresenter.new self, @api
end
|
Instance Attribute Details
39
40
41
|
# File 'lib/gapic/presenters/method_presenter.rb', line 39
def http
@http
end
|
#http_bindings ⇒ Array<Gapic::Presenters::Method::HttpBindingsPresenter>
42
43
44
|
# File 'lib/gapic/presenters/method_presenter.rb', line 42
def http_bindings
@http_bindings
end
|
45
46
47
|
# File 'lib/gapic/presenters/method_presenter.rb', line 45
def lro
@lro
end
|
30
31
32
|
# File 'lib/gapic/presenters/method_presenter.rb', line 30
def method
@method
end
|
33
34
35
|
# File 'lib/gapic/presenters/method_presenter.rb', line 33
def rest
@rest
end
|
36
37
38
|
# File 'lib/gapic/presenters/method_presenter.rb', line 36
def routing
@routing
end
|
#type ⇒ String
Returns String representation of this presenter type.
48
49
50
|
# File 'lib/gapic/presenters/method_presenter.rb', line 48
def type
@type
end
|
Instance Method Details
96
97
98
99
|
# File 'lib/gapic/presenters/method_presenter.rb', line 96
def all_snippets transport: nil
configs = @api.snippet_configs_for(@method.full_name) + [nil]
configs.map { |config| SnippetPresenter.new self, @api, config: config, transport: transport }
end
|
#arguments ⇒ Object
170
171
172
173
|
# File 'lib/gapic/presenters/method_presenter.rb', line 170
def arguments
arguments = @method.input.fields.reject(&:output_only?)
arguments.map { |arg| FieldPresenter.new @api, @method.input, arg }
end
|
Returns List of auto populated fields.
176
177
178
179
180
181
|
# File 'lib/gapic/presenters/method_presenter.rb', line 176
def auto_populated_fields
field_names_to_filter = @api.api_metadata.auto_populated_fields_by_method_name[name] || []
@method.input.fields.filter_map do |field|
FieldPresenter.new @api, @method.input, field if field_names_to_filter.include? field.name
end
end
|
#can_generate_rest? ⇒ Boolean
Whether this method can be generated in REST clients
Only methods with http bindings can be generated, and
additionally only unary methods are currently supported.
375
376
377
|
# File 'lib/gapic/presenters/method_presenter.rb', line 375
def can_generate_rest?
rest.can_generate_rest?
end
|
#client_streaming? ⇒ Boolean
282
283
284
|
# File 'lib/gapic/presenters/method_presenter.rb', line 282
def client_streaming?
@method.client_streaming
end
|
#doc_description(transport: nil) ⇒ String
The description as it should appear in YARD docs.
146
147
148
|
# File 'lib/gapic/presenters/method_presenter.rb', line 146
def doc_description transport: nil
@method. transport: transport
end
|
#doc_response_type ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/gapic/presenters/method_presenter.rb', line 150
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
|
#drift_manifest ⇒ Hash
364
365
366
|
# File 'lib/gapic/presenters/method_presenter.rb', line 364
def drift_manifest
{ methods: [name] }
end
|
#fields ⇒ Object
183
184
185
|
# File 'lib/gapic/presenters/method_presenter.rb', line 183
def fields
@method.input.fields.map { |field| FieldPresenter.new @api, @method.input, field }
end
|
#fields_with_first_oneof ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/gapic/presenters/method_presenter.rb', line 187
def fields_with_first_oneof
return fields if @method.input.oneof_decl.empty?
selected_fields = []
have_oneof = []
@method.input.fields.each do |field|
unless field.oneof?
selected_fields << field
next
end
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
|
#generate_yardoc_snippets? ⇒ Boolean
101
102
103
|
# File 'lib/gapic/presenters/method_presenter.rb', line 101
def generate_yardoc_snippets?
@api.generate_yardoc_snippets?
end
|
#grpc_full_name ⇒ String
Fully qualified proto name of the method (namespace.PascalCase)
121
122
123
|
# File 'lib/gapic/presenters/method_presenter.rb', line 121
def grpc_full_name
@method.full_name
end
|
#grpc_method_name ⇒ Object
351
352
353
|
# File 'lib/gapic/presenters/method_presenter.rb', line 351
def grpc_method_name
@method.name
end
|
#grpc_name ⇒ String
Proto name of the method (PascalCase)
115
116
117
|
# File 'lib/gapic/presenters/method_presenter.rb', line 115
def grpc_name
@method.name
end
|
#grpc_service_config ⇒ Object
340
341
342
343
344
345
|
# File 'lib/gapic/presenters/method_presenter.rb', line 340
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
|
#grpc_service_config_presenter ⇒ Object
347
348
349
|
# File 'lib/gapic/presenters/method_presenter.rb', line 347
def grpc_service_config_presenter
GrpcServiceConfigPresenter.new grpc_service_config
end
|
#is_deprecated? ⇒ Boolean
Returns Whether the method is marked as deprecated.
166
167
168
|
# File 'lib/gapic/presenters/method_presenter.rb', line 166
def is_deprecated?
@method.is_deprecated?
end
|
#kind ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/gapic/presenters/method_presenter.rb', line 125
def kind
if client_streaming?
if server_streaming?
:bidi
else
:client
end
elsif server_streaming?
:server
else
:normal
end
end
|
#lro? ⇒ Boolean
Whether this method uses standard (AIP-151) LROs
257
258
259
260
261
|
# File 'lib/gapic/presenters/method_presenter.rb', line 257
def lro?
return paged_response_type == "::Google::Longrunning::Operation" if paged?
return_type == "::Google::Longrunning::Operation"
end
|
#name ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/gapic/presenters/method_presenter.rb', line 105
def name
@name ||= begin
candidate = ActiveSupport::Inflector.underscore @method.name
candidate = "call_#{candidate}" if Gapic::RubyInfo.excluded_method_names.include? candidate
candidate
end
end
|
#nonstandard_lro? ⇒ Boolean
Whether this method uses nonstandard LROs
268
269
270
|
# File 'lib/gapic/presenters/method_presenter.rb', line 268
def nonstandard_lro?
@lro.nonstandard_lro?
end
|
#nonstandard_lro_client ⇒ Gapic::Presenters::Service::LroClientPresenter?
The presenter for the nonstandard LRO client of the kind this method uses
277
278
279
280
|
# File 'lib/gapic/presenters/method_presenter.rb', line 277
def nonstandard_lro_client
return unless nonstandard_lro?
service.nonstandard_lros.find { |model| model.service == @lro.service_full_name }
end
|
#paged? ⇒ Boolean
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
# File 'lib/gapic/presenters/method_presenter.rb', line 290
def paged?
return false if server_streaming?
address = @method.address.join "."
return false if address == "google.cloud.talent.v4beta1.ProfileService.SearchProfiles"
return false if address == "google.cloud.talent.v4beta1.JobService.SearchJobs"
return false if address == "google.cloud.talent.v4beta1.JobService.SearchJobsForAlert"
paged_request?(@method.input) && paged_response?(@method.output)
end
|
#paged_response_repeated_field_name ⇒ String
Returns The name of the repeated field in paginated responses.
317
318
319
320
321
322
323
324
|
# File 'lib/gapic/presenters/method_presenter.rb', line 317
def paged_response_repeated_field_name
return nil unless paged_response? @method.output
repeated_field = @method.output.fields.find do |f|
f.label == :LABEL_REPEATED && f.type == :TYPE_MESSAGE
end
repeated_field.name
end
|
#paged_response_type ⇒ Object
305
306
307
308
309
310
311
312
|
# File 'lib/gapic/presenters/method_presenter.rb', line 305
def paged_response_type
return nil unless paged_response? @method.output
repeated_field = @method.output.fields.find do |f|
f.label == :LABEL_REPEATED && f.type == :TYPE_MESSAGE
end
message_ruby_type repeated_field.message
end
|
#request_type ⇒ Object
207
208
209
|
# File 'lib/gapic/presenters/method_presenter.rb', line 207
def request_type
message_ruby_type @method.input
end
|
#return_type ⇒ Object
211
212
213
|
# File 'lib/gapic/presenters/method_presenter.rb', line 211
def return_type
message_ruby_type @method.output
end
|
#routing_params ⇒ Array<String>
Returns The segment key names.
329
330
331
|
# File 'lib/gapic/presenters/method_presenter.rb', line 329
def routing_params
@http.routing_params
end
|
#routing_params? ⇒ Boolean
Returns Whether any routing params are present.
336
337
338
|
# File 'lib/gapic/presenters/method_presenter.rb', line 336
def routing_params?
@routing.routing_params?
end
|
#samples ⇒ Object
speech_transcribe_sync_gcs.yaml
244
245
246
247
248
249
250
|
# File 'lib/gapic/presenters/method_presenter.rb', line 244
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
286
287
288
|
# File 'lib/gapic/presenters/method_presenter.rb', line 286
def server_streaming?
@method.server_streaming
end
|
79
80
81
|
# File 'lib/gapic/presenters/method_presenter.rb', line 79
def service
@service_presenter
end
|
Return the "primary" snippet for this method. This should be used for
inline snippets.
88
89
90
91
|
# File 'lib/gapic/presenters/method_presenter.rb', line 88
def snippet transport: nil
configs = @api.snippet_configs_for @method.full_name
SnippetPresenter.new self, @api, config: configs.first, transport: transport
end
|
#yield_doc_description ⇒ Object
220
221
222
223
224
|
# File 'lib/gapic/presenters/method_presenter.rb', line 220
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
229
230
231
232
233
234
235
236
237
238
239
240
|
# File 'lib/gapic/presenters/method_presenter.rb', line 229
def yield_params
if lro?
[
YieldParams.new("operation", "::Gapic::Operation")
]
else
[
YieldParams.new("result", return_type),
YieldParams.new("operation", "::GRPC::ActiveCall::Operation")
]
end
end
|
#yields? ⇒ Boolean
215
216
217
218
|
# File 'lib/gapic/presenters/method_presenter.rb', line 215
def yields?
!server_streaming?
end
|