Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Ruby: Update gemspec and add useful metadata files (#1258)
Browse files Browse the repository at this point in the history
* Ruby: Update gemspec and add useful metadata files
  • Loading branch information
landrito authored and swcloud committed May 18, 2017
1 parent 2f4e121 commit 2c2323e
Show file tree
Hide file tree
Showing 17 changed files with 373 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.api.codegen.transformer.ModelToViewTransformer;
import com.google.api.codegen.transformer.ModelTypeTable;
import com.google.api.codegen.transformer.PackageMetadataTransformer;
import com.google.api.codegen.transformer.SurfaceNamer;
import com.google.api.codegen.transformer.TestCaseTransformer;
import com.google.api.codegen.util.ruby.RubyTypeTable;
import com.google.api.codegen.util.testing.StandardValueProducer;
Expand All @@ -39,6 +40,7 @@
import com.google.api.tools.framework.model.Interface;
import com.google.api.tools.framework.model.Method;
import com.google.api.tools.framework.model.Model;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import java.util.List;

Expand All @@ -49,6 +51,8 @@ public class RubyPackageMetadataTransformer implements ModelToViewTransformer {
private static final String README_OUTPUT_FILE = "README.md";
private static final List<String> TOP_LEVEL_FILES =
ImmutableList.of("ruby/Gemfile.snip", "ruby/Rakefile.snip", "LICENSE.snip");
private static final List<String> TOP_LEVEL_DOT_FILES =
ImmutableList.of("ruby/gitignore.snip", "ruby/rubocop.yml.snip", "ruby/yardopts.snip");

private static final String GITHUB_DOC_HOST =
"https://googlecloudplatform.github.io/google-cloud-ruby";
Expand Down Expand Up @@ -78,6 +82,7 @@ public List<String> getTemplateFileNames() {
.add(GEMSPEC_FILE)
.add(README_FILE)
.addAll(TOP_LEVEL_FILES)
.addAll(TOP_LEVEL_DOT_FILES)
.build();
}

Expand All @@ -87,7 +92,8 @@ public List<ViewModel> transform(Model model, GapicProductConfig productConfig)
return ImmutableList.<ViewModel>builder()
.add(generateGemspecView(model, namer))
.add(generateReadmeView(model, productConfig, namer))
.addAll(generateMetadataViews(model, productConfig, namer))
.addAll(generateMetadataViews(model, productConfig, namer, TOP_LEVEL_FILES))
.addAll(generateMetadataViews(model, productConfig, namer, TOP_LEVEL_DOT_FILES, "."))
.build();
}

Expand Down Expand Up @@ -163,10 +169,22 @@ private OptionalArrayMethodView createExampleApiMethodView(GapicMethodContext co
}

private List<ViewModel> generateMetadataViews(
Model model, GapicProductConfig productConfig, RubyPackageMetadataNamer namer) {
Model model,
GapicProductConfig productConfig,
RubyPackageMetadataNamer namer,
List<String> snippets) {
return generateMetadataViews(model, productConfig, namer, snippets, null);
}

private List<ViewModel> generateMetadataViews(
Model model,
GapicProductConfig productConfig,
RubyPackageMetadataNamer namer,
List<String> snippets,
String filePrefix) {
ImmutableList.Builder<ViewModel> views = ImmutableList.builder();
for (String template : TOP_LEVEL_FILES) {
views.add(generateMetadataView(model, productConfig, template, namer));
for (String template : snippets) {
views.add(generateMetadataView(model, productConfig, template, namer, filePrefix));
}
return views.build();
}
Expand All @@ -175,9 +193,13 @@ private ViewModel generateMetadataView(
Model model,
GapicProductConfig productConfig,
String template,
RubyPackageMetadataNamer namer) {
RubyPackageMetadataNamer namer,
String filePrefix) {
String noLeadingRubyDir =
template.startsWith(RUBY_PREFIX) ? template.substring(RUBY_PREFIX.length()) : template;
if (!Strings.isNullOrEmpty(filePrefix)) {
noLeadingRubyDir = filePrefix + noLeadingRubyDir;
}
int extensionIndex = noLeadingRubyDir.lastIndexOf(".");
String outputPath = noLeadingRubyDir.substring(0, extensionIndex);

Expand All @@ -190,15 +212,16 @@ private ViewModel generateMetadataView(
}
}

SurfaceNamer surfaceNamer = new RubySurfaceNamer(productConfig.getPackageName());

return metadataTransformer
.generateMetadataView(packageConfig, model, template, outputPath, TargetLanguage.RUBY)
.identifier(namer.getMetadataIdentifier())
.fileHeader(
fileHeaderTransformer.generateFileHeader(
productConfig,
ImportSectionView.newBuilder().build(),
new RubySurfaceNamer(productConfig.getPackageName())))
productConfig, ImportSectionView.newBuilder().build(), surfaceNamer))
.hasSmokeTests(hasSmokeTests)
.versionPath(surfaceNamer.getVersionIndexFileImportName())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public String resourceRoot() {

public abstract String protoPath();

@Nullable
public abstract String versionPath();

public abstract String author();

public abstract String email();
Expand Down Expand Up @@ -191,6 +194,8 @@ public abstract static class Builder {
/** The path to the API protos in the googleapis repo. */
public abstract Builder protoPath(String val);

public abstract Builder versionPath(String val);

/** The author of the package. */
public abstract Builder author(String val);

Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/com/google/api/codegen/ruby/Gemfile.snip
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@

gemspec

gem "rake", "~> 11.0"
gem "gcloud-jsondoc",
git: "https://github.com/GoogleCloudPlatform/google-cloud-ruby.git",
branch: "gcloud-jsondoc"

@# TEMP: rainbow (a dependency of rubocop) version 2.2 seems to have a problem,
@# so pinning to 2.1 for now.
gem "rainbow", "~> 2.1.0"
@end
51 changes: 24 additions & 27 deletions src/main/resources/com/google/api/codegen/ruby/gemspec.snip
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,33 @@
@# -*- ruby -*-
@# encoding: utf-8

Gem::Specification.new do |s|
s.name = "{@metadata.identifier}"
s.version = "{@metadata.packageVersionBound.lower}"

s.authors = ["{@metadata.author}"]
s.description = "{@metadata.fullName} client for Ruby."
s.email = "{@metadata.email}"
s.files = Dir.glob(File.join("lib", "**", "*.rb"))
s.files += Dir.glob(File.join('lib', '**', '*.json'))
s.files += %w(Rakefile README.md LICENSE)
s.homepage = "{@metadata.homepage}"
s.license = "{@metadata.licenseName}"
s.platform = Gem::Platform::RUBY
s.require_paths = ["lib"]
s.required_ruby_version = ">= 2.0.0"
s.requirements << "libgrpc ~> 1.0 needs to be installed"
s.summary = "GRPC library for {@metadata.fullName}"

s.add_dependency "grpc", "~> {@metadata.grpcVersionBound.lower}"
s.add_dependency "googleauth", "~> {@metadata.authVersionBound.lower}"
s.add_dependency "google-gax", "~> {@metadata.gaxVersionBound.lower}"
Gem::Specification.new do |gem|
gem.name = "{@metadata.identifier}"
gem.version = "{@metadata.packageVersionBound.lower}"

gem.authors = ["{@metadata.author}"]
gem.email = "{@metadata.email}"
gem.description = "{@metadata.identifier} is the official library for {@metadata.fullName}."
gem.summary = "API Client library for {@metadata.fullName}"
gem.homepage = "{@metadata.homepage}"
gem.license = "{@metadata.licenseName}"

gem.platform = Gem::Platform::RUBY

gem.files = `git ls-files -- lib/*`.split("\n") +
["README.md", "LICENSE", ".yardopts"]
gem.require_paths = ["lib"]

gem.required_ruby_version = ">= 2.0.0"

gem.add_dependency "google-gax", "~> {@metadata.gaxVersionBound.lower}"
@join packageDep : metadata.protoPackageDependencies
s.add_dependency "{@packageDep.name}", "~> {@packageDep.versionBound.lower}"
gem.add_dependency "{@packageDep.name}", "~> {@packageDep.versionBound.lower}"
@end

s.add_development_dependency "bundler", "~> 1.9"
s.add_development_dependency "rake", "~> 10.4"
s.add_development_dependency "rubocop", "~> 0.32"
s.add_development_dependency "simplecov", "~> 0.9"
s.add_development_dependency "minitest", "~> 5.10"
gem.add_development_dependency "minitest", "~> 5.10"
gem.add_development_dependency "rubocop", "<= 0.35.1"
gem.add_development_dependency "simplecov", "~> 0.9"
end

@end
15 changes: 15 additions & 0 deletions src/main/resources/com/google/api/codegen/ruby/gitignore.snip
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@snippet generate(metadata)
Gemfile.lock
coverage/*
doc/*
pkg/*
html/*
jsondoc/*

@# Ignore YARD stuffs
.yardoc

@# IDE settings
.idea
*.iml
@end
56 changes: 56 additions & 0 deletions src/main/resources/com/google/api/codegen/ruby/rubocop.yml.snip
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@snippet generate(metadata)
AllCops:
Exclude:
- "{@metadata.identifier}.gemspec"
- "lib/{@metadata.protoPath}/**/*"
# This should be removed in the future after we are sanitizing client files.
- "lib/{@metadata.versionPath}/**/*"
- "Rakefile"
- "test/**/*"

Documentation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes
Style/MethodDefParentheses:
EnforcedStyle: require_no_parentheses
Style/NumericLiterals:
Enabled: false
Style/SpaceAroundOperators:
Enabled: false
Metrics/ClassLength:
Enabled: false
Style/EmptyLines:
Enabled: false
Style/EmptyElse:
Enabled: false
Style/HashSyntax:
Exclude:
- "lib/{@metadata.versionPath}/**/*"
Metrics/LineLength:
Exclude:
- "lib/{@metadata.versionPath}/**/*"
Metrics/CyclomaticComplexity:
Max: 10
Metrics/PerceivedComplexity:
Max: 10
Metrics/AbcSize:
Max: 25
Exclude:
- "lib/{@metadata.versionPath}/**/*"
Metrics/MethodLength:
Max: 20
Exclude:
- "lib/{@metadata.versionPath}/**/*"
Metrics/ParameterLists:
Enabled: false
Style/RescueModifier:
Enabled: false
Style/ClassVars:
Enabled: false
Style/TrivialAccessors:
Enabled: false
Style/FileName:
Enabled: false
@end
10 changes: 10 additions & 0 deletions src/main/resources/com/google/api/codegen/ruby/yardopts.snip
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@snippet generate(metadata)
--no-private
--title={@metadata.fullName}
--exclude lib/{@metadata.versionPath}
--markup markdown

./lib/**/*.rb
-
README.md
@end
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
source 'https://rubygems.org'

gemspec

gem "rake", "~> 11.0"
gem "gcloud-jsondoc",
git: "https://github.com/GoogleCloudPlatform/google-cloud-ruby.git",
branch: "gcloud-jsondoc"

# TEMP: rainbow (a dependency of rubocop) version 2.2 seems to have a problem,
# so pinning to 2.1 for now.
gem "rainbow", "~> 2.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
source 'https://rubygems.org'

gemspec

gem "rake", "~> 11.0"
gem "gcloud-jsondoc",
git: "https://github.com/GoogleCloudPlatform/google-cloud-ruby.git",
branch: "gcloud-jsondoc"

# TEMP: rainbow (a dependency of rubocop) version 2.2 seems to have a problem,
# so pinning to 2.1 for now.
gem "rainbow", "~> 2.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@
# -*- ruby -*-
# encoding: utf-8

Gem::Specification.new do |s|
s.name = "library"
s.version = "0.6.8"

s.authors = ["Google, Inc."]
s.description = "Google Example Library API client for Ruby."
s.email = "googleapis-packages@google.com"
s.files = Dir.glob(File.join("lib", "**", "*.rb"))
s.files += Dir.glob(File.join('lib', '**', '*.json'))
s.files += %w(Rakefile README.md LICENSE)
s.homepage = "https://github.com/googleapis/googleapis"
s.license = "Apache-2.0"
s.platform = Gem::Platform::RUBY
s.require_paths = ["lib"]
s.required_ruby_version = ">= 2.0.0"
s.requirements << "libgrpc ~> 1.0 needs to be installed"
s.summary = "GRPC library for Google Example Library API"

s.add_dependency "grpc", "~> 1.0"
s.add_dependency "googleauth", "~> 0.5.1"
s.add_dependency "google-gax", "~> 0.8.0"
s.add_dependency "google-common-protos", "~> 1.3.1"
s.add_dependency "google-some-other-package-v1", "~> 0.2.1"

s.add_development_dependency "bundler", "~> 1.9"
s.add_development_dependency "rake", "~> 10.4"
s.add_development_dependency "rubocop", "~> 0.32"
s.add_development_dependency "simplecov", "~> 0.9"
s.add_development_dependency "minitest", "~> 5.10"
Gem::Specification.new do |gem|
gem.name = "library"
gem.version = "0.6.8"

gem.authors = ["Google, Inc."]
gem.email = "googleapis-packages@google.com"
gem.description = "library is the official library for Google Example Library API."
gem.summary = "API Client library for Google Example Library API"
gem.homepage = "https://github.com/googleapis/googleapis"
gem.license = "Apache-2.0"

gem.platform = Gem::Platform::RUBY

gem.files = `git ls-files -- lib/*`.split("\n") +
["README.md", "LICENSE", ".yardopts"]
gem.require_paths = ["lib"]

gem.required_ruby_version = ">= 2.0.0"

gem.add_dependency "google-gax", "~> 0.8.0"
gem.add_dependency "google-common-protos", "~> 1.3.1"
gem.add_dependency "google-some-other-package-v1", "~> 0.2.1"

gem.add_development_dependency "minitest", "~> 5.10"
gem.add_development_dependency "rubocop", "<= 0.35.1"
gem.add_development_dependency "simplecov", "~> 0.9"
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
============== file: .gitignore ==============
Gemfile.lock
coverage/*
doc/*
pkg/*
html/*
jsondoc/*

# Ignore YARD stuffs
.yardoc

# IDE settings
.idea
*.iml
Loading

0 comments on commit 2c2323e

Please sign in to comment.