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

Ruby: Update gemspec and add useful metadata files #1258

Merged
merged 3 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
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.util.ruby.RubyTypeTable;
import com.google.api.codegen.viewmodel.ImportSectionView;
import com.google.api.codegen.viewmodel.ViewModel;
import com.google.api.tools.framework.model.Interface;
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 @@ -37,6 +39,8 @@ public class RubyPackageMetadataTransformer implements ModelToViewTransformer {
private static final List<String> TOP_LEVEL_FILES =
ImmutableList.of(
"ruby/Gemfile.snip", "ruby/Rakefile.snip", "ruby/README.md.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 final FileHeaderTransformer fileHeaderTransformer =
new FileHeaderTransformer(new RubyImportSectionTransformer());
private final PackageMetadataConfig packageConfig;
Expand All @@ -50,15 +54,20 @@ public RubyPackageMetadataTransformer(PackageMetadataConfig packageConfig) {

@Override
public List<String> getTemplateFileNames() {
return ImmutableList.<String>builder().add(GEMSPEC_FILE).addAll(TOP_LEVEL_FILES).build();
return ImmutableList.<String>builder()
.add(GEMSPEC_FILE)
.addAll(TOP_LEVEL_FILES)
.addAll(TOP_LEVEL_DOT_FILES)
.build();
}

@Override
public List<ViewModel> transform(Model model, GapicProductConfig productConfig) {
RubyPackageMetadataNamer namer = new RubyPackageMetadataNamer(productConfig.getPackageName());
return ImmutableList.<ViewModel>builder()
.add(generateGemspecView(model, 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 All @@ -71,10 +80,22 @@ private ViewModel generateGemspecView(Model model, RubyPackageMetadataNamer name
}

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 @@ -83,9 +104,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 @@ -98,15 +123,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 @@ -84,6 +84,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 @@ -169,6 +172,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"

This comment was marked as spam.

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

@end
11 changes: 11 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,11 @@
@snippet generate(metadata)
Gemfile.lock
coverage/*

This comment was marked as spam.

This comment was marked as spam.

doc/*
pkg/*
html/*
jsondoc/*

# Ignore YARD stuffs
.yardoc
@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,9 @@
============== file: .gitignore ==============
Gemfile.lock
coverage/*
doc/*
pkg/*
html/*
jsondoc/*

.yardoc
Loading