lib/gapic/presenters/service_presenter.rb in gapic-generator-0.7.2 vs lib/gapic/presenters/service_presenter.rb in gapic-generator-0.7.4
- old
+ new
@@ -25,15 +25,19 @@
#
class ServicePresenter
include Gapic::Helpers::FilepathHelper
include Gapic::Helpers::NamespaceHelper
+ # @return [Gapic::Presenters::ServiceRestPresenter]
+ attr_reader :rest
+
def initialize gem_presenter, api, service, parent_service: nil
@gem_presenter = gem_presenter
@api = api
@service = service
@parent_service = parent_service
+ @rest = ServiceRestPresenter.new self, api
end
def gem
@gem_presenter
end
@@ -44,14 +48,15 @@
def package
PackagePresenter.new @gem_presenter, @api, @service.parent.package
end
+ ##
+ # @return [Enumerable<Gapic::Presenters::MethodPresenter>]
+ #
def methods
- @methods ||= begin
- @service.methods.map { |m| MethodPresenter.new self, @api, m }
- end
+ @methods ||= @service.methods.map { |m| MethodPresenter.new self, @api, m }
end
def address
@service.address
end
@@ -269,10 +274,33 @@
def paths_require
ruby_file_path @api, "#{service_name_full}::#{paths_name}"
end
+ def generate_rest_clients?
+ @api.generate_rest_clients?
+ end
+
+ def generate_grpc_clients?
+ @api.generate_grpc_clients?
+ end
+
+ ##
+ # @return [Boolean] whether this service contains any methods with REST bindings
+ #
+ def methods_rest_bindings?
+ methods_rest_bindings.any?
+ end
+
+ ##
+ # @return [Enumerable<Gapic::Presenters::MethodPresenter>]
+ # List of mods for which REST bindings are present and REST methods can be generated
+ #
+ def methods_rest_bindings
+ methods.select { |method| method.rest.path? && method.rest.verb? }
+ end
+
def test_client_file_path
service_file_path.sub ".rb", "_test.rb"
end
def test_paths_file_path
@@ -359,13 +387,23 @@
libraryClient: client_name_full,
# The methods should grouped by grpc_method_name and then
# their names are returned together in an array.
# For Ruby currently we have 1:1 proto to code
# correspondence for methods, so our generation is easier
- methods: methods.map { |m| [m.grpc_method_name, [m.name]] }.to_h
+ rpcs: methods.map { |m| [m.grpc_method_name, m.drift_manifest] }.to_h
}
}
}
+ end
+
+ ##
+ # How comments in the generated libraries refer to the GRPC client
+ # if no REST code is generated, this should just be "client",
+ # if REST code is generated, this should be disambiguated into the "GRPC client"
+ #
+ # @return [String]
+ def grpc_client_designation
+ generate_rest_clients? ? "GRPC client" : "client"
end
private
def default_config key