Class: Gapic::Presenters::ServiceRestPresenter
- Inherits:
-
Object
- Object
- Gapic::Presenters::ServiceRestPresenter
- Extended by:
- Forwardable
- Includes:
- Helpers::FilepathHelper, Helpers::NamespaceHelper
- Defined in:
- lib/gapic/presenters/service_rest_presenter.rb
Overview
A presenter for proto service (REST submethods)
Instance Method Summary collapse
-
#api_version ⇒ String
The api_version for this service, or empty if not defined.
- #client_file_path ⇒ String
- #client_name_full ⇒ String
- #client_require ⇒ String
- #configure_client_call ⇒ String
- #create_client_call ⇒ String
-
#helpers_require ⇒ String
Require string for the helpers file.
-
#initialize(main_service, api) ⇒ ServiceRestPresenter
constructor
A new instance of ServiceRestPresenter.
-
#is_deprecated? ⇒ Boolean
Whether the service is marked as deprecated.
-
#lro? ⇒ Boolean
Whether an AIP-151 LRO subclient needs to be generated for this service.
-
#lro_client_presenter ⇒ Gapic::Presenters::Service::LroClientPresenter?
A presenter for the LRO subclient if needed.
- #lro_subclients ⇒ Object
-
#methods ⇒ Enumerable<Gapic::Presenters::MethodPresenter>
Presenters for methods that can be generated in REST clients.
-
#mixin_presenters ⇒ Enumerable<Gapic::Presenters::Service::MixinClientPresenter>
The client presenters of the mixin services that are used by the methods of this service.
-
#mixin_should_generate_override_config? ⇒ Boolean
Whether config for this service should include the
bindings_overridefield. -
#nonstandard_lro_file_name ⇒ String
File name of the nonstandard LRO module.
-
#nonstandard_lro_file_path ⇒ String
Full file path to the nonstandard LRO module.
-
#nonstandard_lro_name ⇒ String
Name of the nonstandard LRO module.
-
#nonstandard_lro_name_full ⇒ String
Full name of the nonstandard LRO module.
-
#nonstandard_lro_require ⇒ String
The require string for the nonstandard LRO module.
-
#nonstandard_lros ⇒ Enumerable<Gapic::Presenters::Service::LroClientPresenter>
The client presenters of the nonstandard LROs that are used by the methods of this service.
-
#numeric_enums? ⇒ Boolean
Whether this rest service should send the numeric enums signal.
- #operations_file_name ⇒ Object
- #operations_file_path ⇒ Object
- #operations_name ⇒ Object
- #operations_name_full ⇒ Object
- #operations_require ⇒ Object
- #operations_stub_name ⇒ Object
-
#quick_start_method ⇒ Gapic::Presenters::MethodRestPresenter?
The method to use for quick start samples.
-
#service_directory_name ⇒ String
Folder name for this service This is just "rest" for rest services.
-
#service_name_full ⇒ String
Full Ruby name of this service.
-
#service_require ⇒ String
Require path for this service.
- #service_rest_file_path ⇒ String
- #service_rest_require ⇒ String
- #service_stub_file_path ⇒ String
- #service_stub_name ⇒ String
- #service_stub_name_full ⇒ String
- #service_stub_require ⇒ String
-
#subclients ⇒ Enumerable<Gapic::Presenters::Service::LroClientPresenter, Gapic::Model::Mixins::Mixin>
Subclients for this service Subclients are the clients to other services (e.g. an LRO provider service).
-
#subclients? ⇒ Boolean
Whether there are any subclients to generate with this service.
- #test_client_file_path ⇒ String
Methods included from Helpers::NamespaceHelper
#ensure_absolute_namespace, #fix_namespace, #ruby_namespace, #ruby_namespace_for_address
Methods included from Helpers::FilepathHelper
#fix_file_path, #ruby_file_path, #ruby_file_path_for_namespace
Constructor Details
#initialize(main_service, api) ⇒ ServiceRestPresenter
Returns a new instance of ServiceRestPresenter.
47 48 49 50 51 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 47 def initialize main_service, api @main_service = main_service @api = api @type = "service" end |
Instance Method Details
#api_version ⇒ String
Returns The api_version for this service, or empty if not defined.
385 386 387 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 385 def api_version @main_service.api_version.to_s end |
#client_file_path ⇒ String
126 127 128 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 126 def client_file_path "#{client_require}.rb" end |
#client_name_full ⇒ String
112 113 114 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 112 def client_name_full fix_namespace api, "#{service_name_full}::#{client_name}" end |
#client_require ⇒ String
119 120 121 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 119 def client_require ruby_file_path api, client_name_full end |
#configure_client_call ⇒ String
161 162 163 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 161 def configure_client_call "#{client_name_full}.configure" end |
#create_client_call ⇒ String
133 134 135 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 133 def create_client_call "#{client_name_full}.new" end |
#helpers_require ⇒ String
Require string for the helpers file
365 366 367 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 365 def helpers_require ruby_file_path @api, "#{service_name_full}::Helpers" end |
#is_deprecated? ⇒ Boolean
Returns Whether the service is marked as deprecated.
380 381 382 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 380 def is_deprecated? @main_service.is_deprecated? end |
#lro? ⇒ Boolean
Whether an AIP-151 LRO subclient needs to be generated for this service
228 229 230 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 228 def lro? methods.find(&:lro?) end |
#lro_client_presenter ⇒ Gapic::Presenters::Service::LroClientPresenter?
A presenter for the LRO subclient if needed
214 215 216 217 218 219 220 221 222 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 214 def lro_client_presenter return nil unless lro? Gapic::Presenters::Service::LroClientPresenter.new service: "google.longrunning.operations", client_class_name: "Operations", client_class_docname: operations_name_full, client_var_name: lro_client_var, require_str: operations_file_path, service_description: "long-running operations" end |
#lro_subclients ⇒ Object
334 335 336 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 334 def lro_subclients [lro_client_presenter, nonstandard_lros].flatten.compact end |
#methods ⇒ Enumerable<Gapic::Presenters::MethodPresenter>
Presenters for methods that can be generated in REST clients.
356 357 358 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 356 def methods main_service.methods.select(&:can_generate_rest?) end |
#mixin_presenters ⇒ Enumerable<Gapic::Presenters::Service::MixinClientPresenter>
The client presenters of the mixin services that are used by the methods of this service
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 295 def mixin_presenters return [] unless main_service.mixins? main_service.mixin_presenters.map do |grpc_presenter| model = main_service.mixin_models.find { |mdl| mdl.service == grpc_presenter.service } raise "Mismatch between model and presenters in service #{service_name_full}" unless model Gapic::Presenters::Service::MixinClientPresenter.new service: model.service, client_class_name: model.client_class_name_rest, client_class_docname: model.client_class_docname_rest, client_var_name: model.client_var_name, require_str: model.require_str_rest, service_description: model.service_description, bindings_override: grpc_presenter.bindings_override end end |
#mixin_should_generate_override_config? ⇒ Boolean
Whether config for this service should include the bindings_override field.
This field is needed:
- if a service is a mixin in it's own package, e.g.
google.Cloud.Location - if a service hosts a mixin and has bindings overrides for it but the generated Operations clients should not have it since override for their bindings are generated instead of set during runtime.
286 287 288 289 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 286 def mixin_should_generate_override_config? (is_main_mixin_service? || main_service.mixin_binding_overrides?) && main_service.grpc_full_name != "google.longrunning.Operations" end |
#nonstandard_lro_file_name ⇒ String
File name of the nonstandard LRO module
197 198 199 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 197 def nonstandard_lro_file_name nonstandard_lro_file_path.split("/").last end |
#nonstandard_lro_file_path ⇒ String
Full file path to the nonstandard LRO module
188 189 190 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 188 def nonstandard_lro_file_path "#{nonstandard_lro_require}.rb" end |
#nonstandard_lro_name ⇒ String
Name of the nonstandard LRO module
170 171 172 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 170 def nonstandard_lro_name "NonstandardLro" end |
#nonstandard_lro_name_full ⇒ String
Full name of the nonstandard LRO module
179 180 181 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 179 def nonstandard_lro_name_full fix_namespace @api, "#{service_name_full}::#{nonstandard_lro_name}" end |
#nonstandard_lro_require ⇒ String
The require string for the nonstandard LRO module
206 207 208 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 206 def nonstandard_lro_require ruby_file_path @api, "#{service_name_full}::#{nonstandard_lro_name}" end |
#nonstandard_lros ⇒ Enumerable<Gapic::Presenters::Service::LroClientPresenter>
The client presenters of the nonstandard LROs that are used by the methods of this service
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 260 def nonstandard_lros return [] unless main_service.nonstandard_lro_consumer? main_service.nonstandard_lros_models.map do |lro| lro_wrapper = @api.lookup lro.service_full_name lro_service = ServicePresenter.new(main_service.gem, @api, lro_wrapper).rest service_description = "long-running operations via #{lro_service.name}" client_var_name = ruby_file_path_for_namespace lro_service.name Gapic::Presenters::Service::LroClientPresenter.new service: lro.service_full_name, client_class_name: lro_service.client_name_full, client_class_docname: lro_service.client_name_full, client_var_name: client_var_name, require_str: lro_service.service_require, service_description: service_description, helper_type: lro_service.nonstandard_lro_name_full end end |
#numeric_enums? ⇒ Boolean
Whether this rest service should send the numeric enums signal
373 374 375 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 373 def numeric_enums? main_service.gem.rest_numeric_enums? end |
#operations_file_name ⇒ Object
244 245 246 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 244 def operations_file_name operations_file_path.split("/").last end |
#operations_file_path ⇒ Object
240 241 242 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 240 def operations_file_path "#{operations_require}.rb" end |
#operations_name ⇒ Object
232 233 234 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 232 def operations_name "Operations" end |
#operations_name_full ⇒ Object
236 237 238 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 236 def operations_name_full fix_namespace @api, "#{service_name_full}::#{operations_name}" end |
#operations_require ⇒ Object
248 249 250 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 248 def operations_require ruby_file_path @api, "#{service_name_full}::#{operations_name}" end |
#operations_stub_name ⇒ Object
252 253 254 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 252 def operations_stub_name "OperationsServiceStub" end |
#quick_start_method ⇒ Gapic::Presenters::MethodRestPresenter?
The method to use for quick start samples. Normally this is simply the first non-client-streaming method defined, but it can be overridden via a gem config.
347 348 349 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 347 def quick_start_method main_service.quick_start_method&.rest end |
#service_directory_name ⇒ String
Folder name for this service This is just "rest" for rest services
77 78 79 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 77 def service_directory_name "rest" end |
#service_name_full ⇒ String
Full Ruby name of this service
58 59 60 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 58 def service_name_full fix_namespace api, "#{main_service.service_name_full}::Rest" end |
#service_require ⇒ String
Require path for this service
67 68 69 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 67 def service_require ruby_file_path @api, service_name_full end |
#service_rest_file_path ⇒ String
147 148 149 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 147 def service_rest_file_path "#{service_rest_require}.rb" end |
#service_rest_require ⇒ String
140 141 142 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 140 def service_rest_require ruby_file_path api, service_name_full end |
#service_stub_file_path ⇒ String
105 106 107 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 105 def service_stub_file_path "#{service_stub_require}.rb" end |
#service_stub_name ⇒ String
84 85 86 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 84 def service_stub_name "ServiceStub" end |
#service_stub_name_full ⇒ String
91 92 93 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 91 def service_stub_name_full fix_namespace api, "#{service_name_full}::#{service_stub_name}" end |
#service_stub_require ⇒ String
98 99 100 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 98 def service_stub_require ruby_file_path api, service_stub_name_full end |
#subclients ⇒ Enumerable<Gapic::Presenters::Service::LroClientPresenter, Gapic::Model::Mixins::Mixin>
Subclients for this service Subclients are the clients to other services (e.g. an LRO provider service).
The following is typically generated for a subclient:
- a require statement for the subclient's class
- a class-level variable in the host service's client
- a code to initialize this variable with a subclient's class instance in the host service's constructor
330 331 332 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 330 def subclients [lro_client_presenter, mixin_presenters, nonstandard_lros].flatten.compact end |
#subclients? ⇒ Boolean
Whether there are any subclients to generate with this service. Subclients are the clients to other services (e.g. an LRO provider service).
316 317 318 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 316 def subclients? subclients.any? end |
#test_client_file_path ⇒ String
154 155 156 |
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 154 def test_client_file_path main_service.service_file_path.sub ".rb", "_rest_test.rb" end |