Class: Gapic::Presenters::MethodPresenter

Inherits:
Object
  • Object
show all
Includes:
Helpers::NamespaceHelper
Defined in:
lib/gapic/presenters/method_presenter.rb

Overview

A presenter for rpc methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::NamespaceHelper

#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.

Parameters:



48
49
50
51
52
53
54
55
56
57
# File 'lib/gapic/presenters/method_presenter.rb', line 48

def initialize service_presenter, api, method
  @service_presenter = service_presenter
  @api = api
  @method = method
  @http = Gapic::Model::Method::HttpAnnotation.new @method
  @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

#httpGapic::Model::Method::HttpAnnotation



39
40
41
# File 'lib/gapic/presenters/method_presenter.rb', line 39

def http
  @http
end

#lroGapic::Model::Method::AipLro, ...



42
43
44
# File 'lib/gapic/presenters/method_presenter.rb', line 42

def lro
  @lro
end

#methodGapic::Schema::Method



30
31
32
# File 'lib/gapic/presenters/method_presenter.rb', line 30

def method
  @method
end

#restGapic::Presenters::MethodRestPresenter



33
34
35
# File 'lib/gapic/presenters/method_presenter.rb', line 33

def rest
  @rest
end

#routingGapic::Model::Method::Routing



36
37
38
# File 'lib/gapic/presenters/method_presenter.rb', line 36

def routing
  @routing
end

Instance Method Details

#argumentsObject



123
124
125
126
# File 'lib/gapic/presenters/method_presenter.rb', line 123

def arguments
  arguments = @method.input.fields.reject(&:output_only?)
  arguments.map { |arg| FieldPresenter.new @api, @method.input, arg }
end

#client_streaming?Boolean

Returns:

  • (Boolean)


232
233
234
# File 'lib/gapic/presenters/method_presenter.rb', line 232

def client_streaming?
  @method.client_streaming
end

#doc_descriptionObject



99
100
101
# File 'lib/gapic/presenters/method_presenter.rb', line 99

def doc_description
  @method.docs_leading_comments
end

#doc_response_typeObject



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/gapic/presenters/method_presenter.rb', line 103

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_manifestHash

Returns a hash with a drift_manifest of this rpc method describing correspondence between the proto description of the rpc with the generated code for the method. For ruby currently [03/2021] only one method is generated per RPC, so the correspondence is very basic. See https://github.com/googleapis/googleapis/blob/master/gapic/metadata/gapic_metadata.proto

Returns:

  • (Hash)


303
304
305
# File 'lib/gapic/presenters/method_presenter.rb', line 303

def drift_manifest
  { methods: [name] }
end

#fieldsObject



128
129
130
# File 'lib/gapic/presenters/method_presenter.rb', line 128

def fields
  @method.input.fields.map { |field| FieldPresenter.new @api, @method.input, field }
end

#fields_with_first_oneofObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/gapic/presenters/method_presenter.rb', line 132

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

Returns:

  • (Boolean)


73
74
75
# File 'lib/gapic/presenters/method_presenter.rb', line 73

def generate_yardoc_snippets?
  @api.generate_yardoc_snippets?
end

#grpc_method_nameObject



290
291
292
# File 'lib/gapic/presenters/method_presenter.rb', line 290

def grpc_method_name
  @method.name
end

#grpc_service_configObject



279
280
281
282
283
284
# File 'lib/gapic/presenters/method_presenter.rb', line 279

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_presenterObject



286
287
288
# File 'lib/gapic/presenters/method_presenter.rb', line 286

def grpc_service_config_presenter
  GrpcServiceConfigPresenter.new grpc_service_config
end

#is_deprecated?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/gapic/presenters/method_presenter.rb', line 119

def is_deprecated?
  @method.is_deprecated?
end

#kindObject



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gapic/presenters/method_presenter.rb', line 85

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

Returns:

  • (Boolean)


207
208
209
210
211
# File 'lib/gapic/presenters/method_presenter.rb', line 207

def lro?
  return paged_response_type == "::Google::Longrunning::Operation" if paged?

  return_type == "::Google::Longrunning::Operation"
end

#nameObject



77
78
79
80
81
82
83
# File 'lib/gapic/presenters/method_presenter.rb', line 77

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

Returns:

  • (Boolean)


218
219
220
# File 'lib/gapic/presenters/method_presenter.rb', line 218

def nonstandard_lro?
  @lro.nonstandard_lro?
end

#nonstandard_lro_clientGapic::Presenters::Service::LroClientPresenter?

The presenter for the nonstandard LRO client of the kind this method uses



227
228
229
230
# File 'lib/gapic/presenters/method_presenter.rb', line 227

def nonstandard_lro_client
  return unless nonstandard_lro?
  service.nonstandard_lros.find { |model| model.service == @lro.service_full_name }
end

#paged?Boolean

Returns:

  • (Boolean)


240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/gapic/presenters/method_presenter.rb', line 240

def paged?
  return false if server_streaming? # Cannot page a streaming response

  # HACK(dazuma, 2020-04-06): Two specific RPCs should not be paged.
  # This is an intentionally hard-coded exception (and a temporary one,
  # to be removed when these methods no longer conform to AIP-4233.) For
  # detailed information, see internal link go/actools-talent-pagination.
  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_typeObject



255
256
257
258
259
260
261
262
263
# File 'lib/gapic/presenters/method_presenter.rb', line 255

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_typeObject



152
153
154
# File 'lib/gapic/presenters/method_presenter.rb', line 152

def request_type
  message_ruby_type @method.input
end

#return_typeObject



156
157
158
# File 'lib/gapic/presenters/method_presenter.rb', line 156

def return_type
  message_ruby_type @method.output
end

#routing_paramsArray<String>

Returns The segment key names.

Returns:

  • (Array<String>)

    The segment key names.



268
269
270
# File 'lib/gapic/presenters/method_presenter.rb', line 268

def routing_params
  rest.routing_params
end

#routing_params?Boolean

Returns Whether any routing params are present.

Returns:

  • (Boolean)

    Whether any routing params are present



275
276
277
# File 'lib/gapic/presenters/method_presenter.rb', line 275

def routing_params?
  @routing.routing_params?
end

#samplesObject

speech_transcribe_sync_gcs.yaml



194
195
196
197
198
199
200
# File 'lib/gapic/presenters/method_presenter.rb', line 194

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

Returns:

  • (Boolean)


236
237
238
# File 'lib/gapic/presenters/method_presenter.rb', line 236

def server_streaming?
  @method.server_streaming
end

#serviceGapic::Presenters::ServicePresenter



62
63
64
# File 'lib/gapic/presenters/method_presenter.rb', line 62

def service
  @service_presenter
end

#snippetGapic::Presenters::SnippetPresenter



69
70
71
# File 'lib/gapic/presenters/method_presenter.rb', line 69

def snippet
  SnippetPresenter.new self, @api
end

#yield_doc_descriptionObject



165
166
167
168
169
# File 'lib/gapic/presenters/method_presenter.rb', line 165

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_paramsObject



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/gapic/presenters/method_presenter.rb', line 171

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

Returns:

  • (Boolean)


160
161
162
163
# File 'lib/gapic/presenters/method_presenter.rb', line 160

def yields?
  # Server streaming RCP calls are the only one that does not yield
  !server_streaming?
end