gapic-generator 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +13 -0
- data/CHANGELOG.md +30 -0
- data/CODE_OF_CONDUCT.md +43 -0
- data/CONTRIBUTING.md +28 -0
- data/LICENSE +202 -0
- data/README.md +72 -0
- data/bin/gapic-generator +103 -0
- data/bin/protoc-gen-ruby_gapic +33 -0
- data/default-rubocop.yml +10 -0
- data/gem_templates/binary.erb +20 -0
- data/gem_templates/dockerfile.erb +39 -0
- data/gem_templates/entrypoint.erb +24 -0
- data/gem_templates/gapic_sh.erb +97 -0
- data/gem_templates/gemfile.erb +8 -0
- data/gem_templates/gemspec.erb +36 -0
- data/gem_templates/generator.erb +37 -0
- data/gem_templates/gitignore.erb +10 -0
- data/gem_templates/rakefile.erb +29 -0
- data/gem_templates/readme.erb +69 -0
- data/gem_templates/rubocop.erb +16 -0
- data/gem_templates/shared/_header.erb +4 -0
- data/gem_templates/shared/_license.erb +13 -0
- data/gem_templates/shared/_warning.erb +1 -0
- data/gem_templates/test_generator.erb +13 -0
- data/gem_templates/test_helper.erb +25 -0
- data/gem_templates/version.erb +10 -0
- data/lib/gapic/file_formatter.rb +62 -0
- data/lib/gapic/gem_builder.rb +98 -0
- data/lib/gapic/generator.rb +30 -0
- data/lib/gapic/generator/version.rb +21 -0
- data/lib/gapic/generators/base_generator.rb +91 -0
- data/lib/gapic/generators/default_generator.rb +101 -0
- data/lib/gapic/grpc_service_config/method_config.rb +49 -0
- data/lib/gapic/grpc_service_config/parser.rb +218 -0
- data/lib/gapic/grpc_service_config/parsing_error.rb +25 -0
- data/lib/gapic/grpc_service_config/retry_policy.rb +51 -0
- data/lib/gapic/grpc_service_config/service_config.rb +42 -0
- data/lib/gapic/path_template.rb +35 -0
- data/lib/gapic/path_template/parser.rb +83 -0
- data/lib/gapic/path_template/segment.rb +67 -0
- data/lib/gapic/resource_lookup.rb +91 -0
- data/lib/gapic/runner.rb +76 -0
- data/lib/gapic/schema.rb +17 -0
- data/lib/gapic/schema/api.rb +264 -0
- data/lib/gapic/schema/loader.rb +269 -0
- data/lib/gapic/schema/wrappers.rb +718 -0
- data/lib/google/api/annotations.pb.rb +39 -0
- data/lib/google/api/client.pb.rb +43 -0
- data/lib/google/api/field_behavior.pb.rb +51 -0
- data/lib/google/api/http.pb.rb +60 -0
- data/lib/google/api/resource.pb.rb +80 -0
- data/lib/google/longrunning/operations.pb.rb +115 -0
- data/lib/google/protobuf/any.pb.rb +40 -0
- data/lib/google/protobuf/compiler/plugin.pb.rb +72 -0
- data/lib/google/protobuf/descriptor.pb.rb +359 -0
- data/lib/google/protobuf/empty.pb.rb +36 -0
- data/lib/google/rpc/status.pb.rb +46 -0
- data/templates/default/gem/_version.erb +2 -0
- data/templates/default/gem/changelog.erb +3 -0
- data/templates/default/gem/gemfile.erb +4 -0
- data/templates/default/gem/gemspec.erb +37 -0
- data/templates/default/gem/gitignore.erb +18 -0
- data/templates/default/gem/license.erb +22 -0
- data/templates/default/gem/rakefile.erb +27 -0
- data/templates/default/gem/readme.erb +24 -0
- data/templates/default/gem/rubocop.erb +59 -0
- data/templates/default/gem/version.erb +6 -0
- data/templates/default/gem/yardopts.erb +12 -0
- data/templates/default/helpers/default_helper.rb +45 -0
- data/templates/default/helpers/filepath_helper.rb +38 -0
- data/templates/default/helpers/namespace_helper.rb +44 -0
- data/templates/default/helpers/presenter_helper.rb +24 -0
- data/templates/default/helpers/presenters/enum_presenter.rb +35 -0
- data/templates/default/helpers/presenters/enum_value_presenter.rb +33 -0
- data/templates/default/helpers/presenters/field_presenter.rb +146 -0
- data/templates/default/helpers/presenters/file_presenter.rb +53 -0
- data/templates/default/helpers/presenters/gem_presenter.rb +140 -0
- data/templates/default/helpers/presenters/message_presenter.rb +66 -0
- data/templates/default/helpers/presenters/method_presenter.rb +293 -0
- data/templates/default/helpers/presenters/package_presenter.rb +65 -0
- data/templates/default/helpers/presenters/resource_presenter.rb +92 -0
- data/templates/default/helpers/presenters/sample_presenter.rb +74 -0
- data/templates/default/helpers/presenters/service_presenter.rb +276 -0
- data/templates/default/layouts/_ruby.erb +20 -0
- data/templates/default/package.erb +6 -0
- data/templates/default/proto_docs/_enum.erb +13 -0
- data/templates/default/proto_docs/_message.erb +23 -0
- data/templates/default/proto_docs/_proto_file.erb +9 -0
- data/templates/default/proto_docs/proto_file.erb +6 -0
- data/templates/default/proto_docs/readme.erb +5 -0
- data/templates/default/service.erb +8 -0
- data/templates/default/service/client.erb +6 -0
- data/templates/default/service/client/_client.erb +137 -0
- data/templates/default/service/client/_config.erb +155 -0
- data/templates/default/service/client/_credentials.erb +21 -0
- data/templates/default/service/client/_helpers.erb +9 -0
- data/templates/default/service/client/_operations.erb +88 -0
- data/templates/default/service/client/_paths.erb +8 -0
- data/templates/default/service/client/_requires.erb +1 -0
- data/templates/default/service/client/_resource.erb +6 -0
- data/templates/default/service/client/_self_configure.erb +9 -0
- data/templates/default/service/client/_self_configure_defaults.erb +22 -0
- data/templates/default/service/client/_self_configure_retry_policy.erb +15 -0
- data/templates/default/service/client/method/_def.erb +21 -0
- data/templates/default/service/client/method/def/_options_defaults.erb +29 -0
- data/templates/default/service/client/method/def/_request.erb +6 -0
- data/templates/default/service/client/method/def/_request_normal.erb +4 -0
- data/templates/default/service/client/method/def/_request_streaming.erb +9 -0
- data/templates/default/service/client/method/def/_rescue.erb +1 -0
- data/templates/default/service/client/method/def/_response.erb +6 -0
- data/templates/default/service/client/method/def/_response_normal.erb +8 -0
- data/templates/default/service/client/method/def/_response_paged.erb +9 -0
- data/templates/default/service/client/method/docs/_error.erb +2 -0
- data/templates/default/service/client/method/docs/_request.erb +6 -0
- data/templates/default/service/client/method/docs/_request_field.erb +7 -0
- data/templates/default/service/client/method/docs/_request_normal.erb +20 -0
- data/templates/default/service/client/method/docs/_request_streaming.erb +5 -0
- data/templates/default/service/client/method/docs/_response.erb +6 -0
- data/templates/default/service/client/method/docs/_sample.erb +20 -0
- data/templates/default/service/client/method/docs/_sample_response.erb +24 -0
- data/templates/default/service/client/method/docs/_samples.erb +6 -0
- data/templates/default/service/client/method/docs/request_field/_arg.erb +10 -0
- data/templates/default/service/client/method/docs/request_field/_hash.erb +19 -0
- data/templates/default/service/client/method/docs/sample_response/_comment.erb +5 -0
- data/templates/default/service/client/method/docs/sample_response/_define.erb +2 -0
- data/templates/default/service/client/method/docs/sample_response/_loop.erb +12 -0
- data/templates/default/service/client/method/docs/sample_response/_print.erb +2 -0
- data/templates/default/service/client/method/docs/sample_response/_write_file.erb +2 -0
- data/templates/default/service/client/resource/_def.erb +6 -0
- data/templates/default/service/client/resource/_doc.erb +8 -0
- data/templates/default/service/client/resource/_multi.erb +28 -0
- data/templates/default/service/client/resource/_single.erb +11 -0
- data/templates/default/service/credentials.erb +6 -0
- data/templates/default/service/operations.erb +6 -0
- data/templates/default/service/paths.erb +6 -0
- data/templates/default/service/test/client.erb +24 -0
- data/templates/default/service/test/client_operations.erb +24 -0
- data/templates/default/service/test/method/_assert_response.erb +11 -0
- data/templates/default/service/test/method/_bidi.erb +100 -0
- data/templates/default/service/test/method/_client.erb +84 -0
- data/templates/default/service/test/method/_normal.erb +69 -0
- data/templates/default/service/test/method/_server.erb +85 -0
- data/templates/default/service/test/method/_setup.erb +21 -0
- data/templates/default/service/test/smoke.erb +12 -0
- data/templates/default/shared/_header.erb +4 -0
- data/templates/default/shared/_license.erb +21 -0
- data/templates/default/shared/_warning.erb +1 -0
- metadata +350 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
<%- assert_locals gem -%>
|
2
|
+
# -*- ruby -*-
|
3
|
+
# encoding: utf-8
|
4
|
+
require File.expand_path("lib/<%= gem.version_require %>", __dir__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "<%= gem.name %>"
|
8
|
+
gem.version = <%= gem.version_name_full %>
|
9
|
+
|
10
|
+
gem.authors = <%= gem.authors.inspect %>
|
11
|
+
gem.email = <%= gem.email.inspect %>
|
12
|
+
gem.description = <%= gem.description.inspect %>
|
13
|
+
gem.summary = <%= gem.summary.inspect %>
|
14
|
+
gem.homepage = <%= gem.homepage.inspect %>
|
15
|
+
gem.license = "MIT"
|
16
|
+
|
17
|
+
gem.platform = Gem::Platform::RUBY
|
18
|
+
|
19
|
+
gem.files = `git ls-files -- lib/*`.split("\n") +
|
20
|
+
`git ls-files -- proto_docs/*`.split("\n") +
|
21
|
+
["README.md", "LICENSE.md", ".yardopts"]
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
|
24
|
+
gem.required_ruby_version = ">= 2.4"
|
25
|
+
|
26
|
+
gem.add_dependency "gapic-common", "~> 0.1.0"
|
27
|
+
<%- if gem.iam_dependency? -%>
|
28
|
+
gem.add_dependency "grpc-google-iam-v1", "~> 0.6.9"
|
29
|
+
<%- end -%>
|
30
|
+
|
31
|
+
gem.add_development_dependency "google-style", "~> 1.24.0"
|
32
|
+
gem.add_development_dependency "minitest", "~> 5.10"
|
33
|
+
gem.add_development_dependency "rake", ">= 12.0"
|
34
|
+
gem.add_development_dependency "redcarpet", "~> 3.0"
|
35
|
+
gem.add_development_dependency "simplecov", "~> 0.18"
|
36
|
+
gem.add_development_dependency "yard", "~> 0.9"
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%- assert_locals gem -%>
|
2
|
+
# Ignore bundler lockfiles
|
3
|
+
Gemfile.lock
|
4
|
+
gems.locked
|
5
|
+
|
6
|
+
# Ignore documentation output
|
7
|
+
doc/*
|
8
|
+
.yardoc/*
|
9
|
+
|
10
|
+
# Ignore test output
|
11
|
+
coverage/*
|
12
|
+
|
13
|
+
# Ignore build artifacts
|
14
|
+
pkg/*
|
15
|
+
|
16
|
+
# Ignore files commonly present in certain dev environments
|
17
|
+
.vagrant
|
18
|
+
.DS_STORE
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<%- assert_locals gem -%>
|
2
|
+
The MIT License (MIT)
|
3
|
+
|
4
|
+
Copyright <YEAR> <COPYRIGHT HOLDER>
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<%- assert_locals gem -%>
|
2
|
+
<%= render partial: "shared/header" -%>
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "bundler/gem_tasks"
|
6
|
+
|
7
|
+
require "rubocop/rake_task"
|
8
|
+
RuboCop::RakeTask.new
|
9
|
+
|
10
|
+
require "rake/testtask"
|
11
|
+
desc "Run tests."
|
12
|
+
Rake::TestTask.new do |t|
|
13
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
14
|
+
t.warning = false
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run smoke tests."
|
18
|
+
Rake::TestTask.new :smoke_test do |t|
|
19
|
+
t.test_files = FileList["acceptance/**/*smoke_test.rb"]
|
20
|
+
t.warning = false
|
21
|
+
end
|
22
|
+
|
23
|
+
require "yard"
|
24
|
+
require "yard/rake/yardoc_task"
|
25
|
+
YARD::Rake::YardocTask.new
|
26
|
+
|
27
|
+
task default: :test
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# <%= gem.title %>
|
2
|
+
|
3
|
+
<%= gem.description %>
|
4
|
+
|
5
|
+
<%= gem.summary %>
|
6
|
+
|
7
|
+
<%= gem.homepage %>
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install <%= gem.name %>
|
13
|
+
```
|
14
|
+
|
15
|
+
## Supported Ruby Versions
|
16
|
+
|
17
|
+
This library is supported on Ruby 2.4+.
|
18
|
+
|
19
|
+
Google provides official support for Ruby versions that are actively supported
|
20
|
+
by Ruby Core—that is, Ruby versions that are either in normal maintenance or
|
21
|
+
in security maintenance, and not end of life. Currently, this means Ruby 2.4
|
22
|
+
and later. Older versions of Ruby _may_ still work, but are unsupported and not
|
23
|
+
recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
|
24
|
+
about the Ruby support schedule.
|
@@ -0,0 +1,59 @@
|
|
1
|
+
<%- assert_locals gem -%>
|
2
|
+
inherit_gem:
|
3
|
+
google-style: google-style.yml
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- "lib/**/*_pb.rb"
|
8
|
+
- "proto_docs/**/*"
|
9
|
+
- "test/**/*"
|
10
|
+
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Exclude:
|
13
|
+
<%- gem.packages.each do |package| -%>
|
14
|
+
<%- package.services.each do |service| -%>
|
15
|
+
- "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
|
16
|
+
<%- end -%>
|
17
|
+
<%- end -%>
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Exclude:
|
20
|
+
<%- gem.packages.each do |package| -%>
|
21
|
+
<%- package.services.each do |service| -%>
|
22
|
+
- "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
|
23
|
+
<%- end -%>
|
24
|
+
<%- end -%>
|
25
|
+
Metrics/CyclomaticComplexity:
|
26
|
+
Exclude:
|
27
|
+
<%- gem.packages.each do |package| -%>
|
28
|
+
<%- package.services.each do |service| -%>
|
29
|
+
- "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
|
30
|
+
<%- end -%>
|
31
|
+
<%- end -%>
|
32
|
+
Metrics/LineLength:
|
33
|
+
Exclude:
|
34
|
+
<%- gem.packages.each do |package| -%>
|
35
|
+
<%- package.services.each do |service| -%>
|
36
|
+
- "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
|
37
|
+
<%- end -%>
|
38
|
+
<%- end -%>
|
39
|
+
Metrics/MethodLength:
|
40
|
+
Exclude:
|
41
|
+
<%- gem.packages.each do |package| -%>
|
42
|
+
<%- package.services.each do |service| -%>
|
43
|
+
- "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
|
44
|
+
<%- end -%>
|
45
|
+
<%- end -%>
|
46
|
+
Metrics/PerceivedComplexity:
|
47
|
+
Exclude:
|
48
|
+
<%- gem.packages.each do |package| -%>
|
49
|
+
<%- package.services.each do |service| -%>
|
50
|
+
- "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
|
51
|
+
<%- end -%>
|
52
|
+
<%- end -%>
|
53
|
+
Style/CaseEquality:
|
54
|
+
Exclude:
|
55
|
+
<%- gem.packages.each do |package| -%>
|
56
|
+
<%- package.services.each do |service| -%>
|
57
|
+
- "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
|
58
|
+
<%- end -%>
|
59
|
+
<%- end -%>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "active_support/inflector"
|
18
|
+
|
19
|
+
module DefaultHelper
|
20
|
+
def prepend_with input, prepend
|
21
|
+
input
|
22
|
+
.strip
|
23
|
+
.each_line
|
24
|
+
.map { |line| prepend + line }
|
25
|
+
.map { |line| line.blank? ? "\n" : line }
|
26
|
+
.join
|
27
|
+
end
|
28
|
+
|
29
|
+
def indent input, spacing
|
30
|
+
spacing = " " * spacing unless spacing.is_a? String
|
31
|
+
ret = prepend_with input, spacing
|
32
|
+
# Remove trailing whitespace from each line end if present
|
33
|
+
ret.split("\n").map(&:rstrip).join("\n")
|
34
|
+
end
|
35
|
+
|
36
|
+
def indent_tail input, spacing
|
37
|
+
return input if input.lines.count < 2
|
38
|
+
|
39
|
+
input.lines[0] + indent(input.lines[1..-1].join, spacing)
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert_locals *locals
|
43
|
+
locals.each { |local| raise "missing local in template" if local.nil? }
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "active_support/inflector"
|
18
|
+
|
19
|
+
module FilepathHelper
|
20
|
+
##
|
21
|
+
# Converts a ruby namespace string to a file path string.
|
22
|
+
def ruby_file_path api, namespace
|
23
|
+
file_path = ruby_file_path_for_namespace namespace
|
24
|
+
fix_file_path api, file_path
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Converts a ruby namespace string to a file path string.
|
29
|
+
def ruby_file_path_for_namespace namespace
|
30
|
+
ActiveSupport::Inflector.underscore namespace
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Corrects a namespace by replacing known bad values with good values.
|
35
|
+
def fix_file_path api, file_path
|
36
|
+
file_path.split("/").map { |node| api.fix_file_path node }.join("/")
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "active_support/inflector"
|
18
|
+
|
19
|
+
module NamespaceHelper
|
20
|
+
##
|
21
|
+
# Looks up the ruby_package for a dot-separated address string to a new string
|
22
|
+
# and creates the corrected Ruby namespace
|
23
|
+
def ruby_namespace api, address
|
24
|
+
file = api.file_for address
|
25
|
+
address = address.dup
|
26
|
+
address[file.package] = file.ruby_package if file.ruby_package.present?
|
27
|
+
namespace = ruby_namespace_for_address address
|
28
|
+
fix_namespace api, namespace
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Converts an array or dot-separated address string to a new string with
|
33
|
+
# Ruby double-semicolon separators.
|
34
|
+
def ruby_namespace_for_address address
|
35
|
+
address = address.split "." if address.is_a? String
|
36
|
+
address.reject(&:empty?).map(&:camelize).join "::"
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Corrects a namespace by replacing known bad values with good values.
|
41
|
+
def fix_namespace api, namespace
|
42
|
+
namespace.split("::").map { |node| api.fix_namespace node }.join("::")
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "active_support/inflector"
|
18
|
+
require_relative "presenters/gem_presenter"
|
19
|
+
|
20
|
+
module PresenterHelper
|
21
|
+
def gem_presenter api
|
22
|
+
GemPresenter.new api
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require_relative "enum_value_presenter"
|
18
|
+
|
19
|
+
class EnumPresenter
|
20
|
+
def initialize enum
|
21
|
+
@enum = enum
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
@enum.name
|
26
|
+
end
|
27
|
+
|
28
|
+
def doc_description
|
29
|
+
@enum.docs_leading_comments
|
30
|
+
end
|
31
|
+
|
32
|
+
def values
|
33
|
+
@values ||= @enum.values.map { |v| EnumValuePresenter.new v }
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
class EnumValuePresenter
|
18
|
+
def initialize value
|
19
|
+
@value = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@value.name
|
24
|
+
end
|
25
|
+
|
26
|
+
def doc_description
|
27
|
+
@value.docs_leading_comments
|
28
|
+
end
|
29
|
+
|
30
|
+
def number
|
31
|
+
@value.number
|
32
|
+
end
|
33
|
+
end
|