lib/gapic/presenters/service_presenter.rb in gapic-generator-0.5.1 vs lib/gapic/presenters/service_presenter.rb in gapic-generator-0.6.0
- old
+ new
@@ -25,31 +25,32 @@
#
class ServicePresenter
include Gapic::Helpers::FilepathHelper
include Gapic::Helpers::NamespaceHelper
- def initialize api, service, parent_service: nil
+ def initialize gem_presenter, api, service, parent_service: nil
+ @gem_presenter = gem_presenter
@api = api
@service = service
@parent_service = parent_service
end
def gem
- GemPresenter.new @api
+ @gem_presenter
end
def file
FilePresenter.new @api, @service.parent
end
def package
- PackagePresenter.new @api, @service.parent.package
+ PackagePresenter.new @gem_presenter, @api, @service.parent.package
end
def methods
@methods ||= begin
- @service.methods.map { |m| MethodPresenter.new @api, m }
+ @service.methods.map { |m| MethodPresenter.new self, @api, m }
end
end
def address
@service.address
@@ -58,11 +59,11 @@
# Returns a presenter for this service's delegate (if it is a common service)
# otherwise returns `nil`.
def common_service_delegate
unless defined? @common_service_delegate
delegate = @api.delegate_service_for @service
- @common_service_delegate = delegate ? ServicePresenter.new(@api, delegate) : nil
+ @common_service_delegate = delegate ? ServicePresenter.new(@gem_presenter, @api, delegate) : nil
end
@common_service_delegate
end
# The namespace of the client. Normally this is the version module. This
@@ -185,17 +186,22 @@
def client_file_name
client_file_path.split("/").last
end
def client_endpoint
+ return nil if generic_endpoint?
@parent_service&.client_endpoint ||
common_service_delegate&.client_endpoint ||
@service.host ||
default_config(:default_host) ||
"localhost"
end
+ def generic_endpoint?
+ gem.generic_endpoint?
+ end
+
def client_scopes
common_service_delegate&.client_scopes ||
@service.scopes ||
default_config(:oauth_scopes)
end
@@ -312,10 +318,10 @@
ruby_file_path @api, "#{service_name_full}::#{operations_name}"
end
def lro_service
lro = @service.parent.parent.files.find { |file| file.name == "google/longrunning/operations.proto" }
- return ServicePresenter.new @api, lro.services.first, parent_service: self unless lro.nil?
+ return ServicePresenter.new @gem_presenter, @api, lro.services.first, parent_service: self unless lro.nil?
end
def config_channel_args
{ "grpc.service_config_disable_resolution" => 1 }
end