protoc-gen-twirp_ruby 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +19 -24
- data/lib/twirp/protoc_plugin/code_generator.rb +1 -7
- data/lib/twirp/protoc_plugin/core_ext/string/to_anchor.rb +14 -0
- data/lib/twirp/protoc_plugin/process.rb +9 -14
- data/lib/twirp/protoc_plugin/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dae48985eff8d4e3133f64234bf45aa141297f9b8f5e0d516f6ff6c7f9e88d11
|
4
|
+
data.tar.gz: 8feef99527f54ccae5a134e69a5d8f175afa638666fd7664b468ad65a8162347
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b20a7052a82e3fe2ea18bc7d524fb340e0ea275f6330243ded7d987acef6e26c596e069df7288fe76ec48091cc0eefcd18c16430ff4513748d2af2a73eb2273
|
7
|
+
data.tar.gz: 199c42f3b6f8a3952f8f3c6f9d4be6bfbba3944d9349efefb748afd6e00491fa4cb13a3ac19b54f0049b28167e8f975d217b382ceaa88d0d959a3d98f3b55bba
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
1
8
|
## [Unreleased]
|
2
9
|
|
10
|
+
- No notable changes since last release
|
11
|
+
|
12
|
+
## [1.2.0] - 2024-05-29
|
13
|
+
|
14
|
+
- Streamline gem release with rake task - [#41](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/41)
|
15
|
+
- Make `skip-empty` the default behavior; remove recognizing the option flag - [#40](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/40)
|
16
|
+
- Update GitHub action to run specs on all supported Ruby versions - [#37](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/37)
|
17
|
+
|
3
18
|
## [1.1.1] - 2024-05-22
|
4
19
|
|
5
20
|
- Remove unnecessary `racc` runtime dependency - [#33](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/33)
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
[![Gem Version](https://img.shields.io/gem/v/protoc-gen-twirp_ruby.svg)](https://rubygems.org/gems/protoc-gen-twirp_ruby)
|
2
|
-
[![
|
2
|
+
[![Specs](https://github.com/collectiveidea/protoc-gen-twirp_ruby/actions/workflows/rspec.yml/badge.svg)](https://github.com/collectiveidea/protoc-gen-twirp_ruby/actions/workflows/rspec.yml)
|
3
3
|
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/a0020a73103eedbe760c/test_coverage)](https://codeclimate.com/github/collectiveidea/protoc-gen-twirp_ruby/test_coverage)
|
4
5
|
|
5
6
|
# protoc-gen-twirp_ruby - A `protoc` plugin for Twirp-Ruby.
|
6
7
|
|
@@ -52,18 +53,16 @@ protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. ./path/to/service.proto
|
|
52
53
|
|
53
54
|
You can configure the code generation. Pass options by specifying `--twirp_ruby_opt=<option>` on the `protoc` command line.
|
54
55
|
|
55
|
-
* `
|
56
|
-
|
57
|
-
|
58
|
-
* `generate=
|
59
|
-
* `generate=
|
60
|
-
* `generate=both` - generate both services and clients. This is the default option to preserve
|
61
|
-
backwards compatibility.
|
56
|
+
* `generate=<service|client|both>`: Customize generated output to include generated services, clients, or both. Optional,
|
57
|
+
defaults to both to preserve backwards compatibility.
|
58
|
+
* `generate=service` - only generate `::Twirp::Service`s.
|
59
|
+
* `generate=client` - only generate `::Twirp::Client`s.
|
60
|
+
* `generate=both` - default; generate both services and clients.
|
62
61
|
|
63
|
-
Example
|
62
|
+
Example :
|
64
63
|
|
65
64
|
```bash
|
66
|
-
protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. --twirp_ruby_opt=generate=client
|
65
|
+
protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. --twirp_ruby_opt=generate=client ./path/to/service.proto
|
67
66
|
```
|
68
67
|
|
69
68
|
## Migrating from the Go module
|
@@ -83,20 +82,20 @@ that might affect migration include:
|
|
83
82
|
* Generated output code is in [standardrb style](https://github.com/standardrb/standard).
|
84
83
|
* Generated service and client class names are improved for well-named protobuf services. See [#6](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/6).
|
85
84
|
* Supports `ruby_package` in `.proto` files
|
86
|
-
* Supports
|
87
|
-
|
85
|
+
* Supports protoc command line [configuration options](#options).
|
88
86
|
|
89
87
|
## Development
|
90
88
|
|
91
89
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
92
90
|
|
93
|
-
|
91
|
+
To experiment with development changes, route `protoc` to the local plugin when generating code
|
92
|
+
via the `--plugin=protoc-gen-twirp_ruby=./exe/protoc-gen-twirp_ruby` option. For example:
|
94
93
|
|
95
94
|
```bash
|
96
95
|
protoc --plugin=protoc-gen-twirp_ruby=./exe/protoc-gen-twirp_ruby --ruby_out=. --twirp_ruby_out=. ./example/hello_world.proto
|
97
96
|
```
|
98
97
|
|
99
|
-
|
98
|
+
Alternatively, install the local gem before invoking `protoc`:
|
100
99
|
|
101
100
|
```bash
|
102
101
|
bundle exec rake install
|
@@ -105,20 +104,16 @@ protoc --ruby_out=. --twirp_ruby_out=. ./example/hello_world.proto
|
|
105
104
|
|
106
105
|
## Releasing
|
107
106
|
|
107
|
+
Install the [GitHub CLI](https://cli.github.com): `brew install gh` or [follow the instructions](https://github.com/cli/cli#installation).
|
108
|
+
|
108
109
|
To release a new version:
|
109
110
|
|
110
|
-
* Submit a PR with the following changes (see [#30](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/30)):
|
111
|
+
* Submit a PR with the following changes (see e.g. [#30](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/30)):
|
111
112
|
* Update the version number in `version.rb`
|
112
113
|
* Update the CHANGELOG.md
|
113
|
-
|
114
|
-
* Re-generate the example:
|
115
|
-
|
116
|
-
* Once merged, run the release task from main. Note that we prepend `gem_push=no` to avoid
|
117
|
-
pushing to RubyGems directly; our GitHub publish action will do this for us.
|
118
|
-
* `gem_push=no bundle exec rake release`
|
119
|
-
* Create a GitHub release:
|
120
|
-
* `gh release create v<version>`
|
121
|
-
* Edit the release notes to link to the notes in the CHANGELOG.md for the version
|
114
|
+
* Create a section for the new version and move the unreleased version there
|
115
|
+
* Re-generate the example: `bundle exec rake example`
|
116
|
+
* Once merged and `main` is up-to-date, run `bundle exec rake release`.
|
122
117
|
|
123
118
|
## Contributing
|
124
119
|
|
@@ -10,9 +10,7 @@ module Twirp
|
|
10
10
|
class CodeGenerator
|
11
11
|
# @param proto_file [Google::Protobuf::FileDescriptorProto]
|
12
12
|
# @param relative_ruby_protobuf [String] e.g. "example_rb.pb"
|
13
|
-
# @param options [Hash{Symbol =>
|
14
|
-
# * :skip_empty [Boolean] indicating whether generation should skip creating a twirp file
|
15
|
-
# for proto files that contain no services.
|
13
|
+
# @param options [Hash{Symbol => Symbol}]
|
16
14
|
# * :generate [Symbol] one of: :service, :client, or :both.
|
17
15
|
def initialize(proto_file, relative_ruby_protobuf, options)
|
18
16
|
@proto_file = proto_file
|
@@ -42,10 +40,6 @@ module Twirp
|
|
42
40
|
indent_level += 1
|
43
41
|
end
|
44
42
|
|
45
|
-
unless @proto_file.has_service?
|
46
|
-
output << line("# No services found; To skip generating this file, specify `--twirp_ruby_opt=skip-empty`.", indent_level)
|
47
|
-
end
|
48
|
-
|
49
43
|
@proto_file.service.each_with_index do |service, index| # service: <Google::Protobuf::ServiceDescriptorProto>
|
50
44
|
# Add newline between definitions when multiple are generated
|
51
45
|
output << "\n" if index > 0
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
# Converts the string to an acceptable URL anchor.
|
5
|
+
#
|
6
|
+
# Thw rules for GitHub markdown links are:
|
7
|
+
# - force lowercase
|
8
|
+
# - strip punctuation
|
9
|
+
# - replace spaces with dashes
|
10
|
+
# @return [String] the string converted to an acceptable URL anchor
|
11
|
+
def to_anchor
|
12
|
+
downcase.gsub(/[^a-z0-9_ -]/, "").tr(" ", "-")
|
13
|
+
end
|
14
|
+
end
|
@@ -25,7 +25,7 @@ module Twirp
|
|
25
25
|
|
26
26
|
request.proto_file.each do |proto_file| # proto_file: <Google::Protobuf::FileDescriptorProto>
|
27
27
|
next unless request.file_to_generate.include?(proto_file.name)
|
28
|
-
next
|
28
|
+
next unless proto_file.has_service? # do not generate when no services defined
|
29
29
|
|
30
30
|
file = Google::Protobuf::Compiler::CodeGeneratorResponse::File.new
|
31
31
|
file.name = proto_file.twirp_output_filename
|
@@ -39,19 +39,19 @@ module Twirp
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
# @param params [String] the parameters from protoc command line in comma-separated stringified
|
43
|
-
# array format, e.g. "some-flag,key1=value1".
|
42
|
+
# @param params [String] the parameters from `protoc` command line in comma-separated stringified
|
43
|
+
# array format, e.g. "some-flag,key1=value1". For repeated command line options, `protoc` will
|
44
|
+
# add the option multiple times, e.g. "some-flag,key1=value1,key1=twice,key2=value2".
|
44
45
|
#
|
45
|
-
# The only valid parameter is currently the optional "
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# for proto files that contain no services. Default false.
|
46
|
+
# The only valid parameter is currently the optional "generate" parameter.
|
47
|
+
#
|
48
|
+
# @return Hash{Symbol => Symbol} the extracted options, a Hash that contains:
|
49
49
|
# * :generate [Symbol] one of: :service, :client, or :both. Default :both.
|
50
|
+
#
|
50
51
|
# @raise [ArgumentError] when a required parameter is missing, a parameter value is invalid, or
|
51
52
|
# an unrecognized parameter is present on the command line
|
52
53
|
def extract_options(params)
|
53
54
|
opts = {
|
54
|
-
skip_empty: false,
|
55
55
|
generate: :both
|
56
56
|
}
|
57
57
|
|
@@ -60,12 +60,7 @@ module Twirp
|
|
60
60
|
# In the event value contains an =, we want to leave that intact.
|
61
61
|
# Limit the split to just separate the key out.
|
62
62
|
key, value = param.split("=", 2)
|
63
|
-
if key == "
|
64
|
-
unless value.nil? || value.empty?
|
65
|
-
raise ArgumentError, "Unexpected value passed to skip-empty flag: #{value}"
|
66
|
-
end
|
67
|
-
opts[:skip_empty] = true
|
68
|
-
elsif key == "generate"
|
63
|
+
if key == "generate"
|
69
64
|
if value.nil? || value.empty?
|
70
65
|
raise ArgumentError, "Unexpected missing value for generate option. Please supply one of: service, client, both."
|
71
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protoc-gen-twirp_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darron Schall
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-05-
|
13
|
+
date: 2024-05-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: google-protobuf
|
@@ -68,6 +68,20 @@ dependencies:
|
|
68
68
|
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: simplecov
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
71
85
|
- !ruby/object:Gem::Dependency
|
72
86
|
name: standard
|
73
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +117,7 @@ files:
|
|
103
117
|
- lib/twirp/protoc_plugin/core_ext/string/camel_case.rb
|
104
118
|
- lib/twirp/protoc_plugin/core_ext/string/capitalize_first.rb
|
105
119
|
- lib/twirp/protoc_plugin/core_ext/string/snake_case.rb
|
120
|
+
- lib/twirp/protoc_plugin/core_ext/string/to_anchor.rb
|
106
121
|
- lib/twirp/protoc_plugin/descriptor_ext/file_descriptor_proto_ext.rb
|
107
122
|
- lib/twirp/protoc_plugin/descriptor_ext/service_descriptor_proto_ext.rb
|
108
123
|
- lib/twirp/protoc_plugin/process.rb
|