protoc-gen-twirp_ruby 1.1.0 → 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 +18 -1
- data/README.md +58 -42
- 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 +11 -9
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,6 +1,23 @@
|
|
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
|
|
3
|
-
-
|
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
|
+
|
18
|
+
## [1.1.1] - 2024-05-22
|
19
|
+
|
20
|
+
- Remove unnecessary `racc` runtime dependency - [#33](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/33)
|
4
21
|
|
5
22
|
## [1.1.0] - 2024-05-21
|
6
23
|
|
data/README.md
CHANGED
@@ -1,14 +1,22 @@
|
|
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
|
-
# protoc-gen-twirp_ruby
|
6
|
+
# protoc-gen-twirp_ruby - A `protoc` plugin for Twirp-Ruby.
|
6
7
|
|
7
|
-
This gem
|
8
|
+
This gem is a `protoc` plugin that generates [Twirp-Ruby](https://github.com/arthurnn/twirp-ruby) services and clients.
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
## Why use this?
|
11
|
+
|
12
|
+
Twirp-Ruby [already does this](https://github.com/arthurnn/twirp-ruby/tree/main/protoc-gen-twirp_ruby)
|
13
|
+
via a `go` module. So why use this version?
|
14
|
+
|
15
|
+
* Easier install (just add the gem).
|
16
|
+
* You already know and love Ruby.
|
17
|
+
* We're committed to keeping it up to date.
|
18
|
+
|
19
|
+
The Go version works fine (we used it for years) but it was missing features that we wanted. Building in Ruby allows us to iterate quicker and makes it easier for others to contribute.
|
12
20
|
|
13
21
|
## Installation
|
14
22
|
|
@@ -25,70 +33,69 @@ the `--ruby_out` option). It does not generate Twirp services and clients; that
|
|
25
33
|
|
26
34
|
### Install the `protoc-gen-twirp_ruby` plugin
|
27
35
|
|
28
|
-
|
36
|
+
Run `gem install protoc-gen-twirp_ruby` or add it to your Gemfile:
|
29
37
|
|
30
38
|
```ruby
|
31
|
-
|
32
|
-
"protoc-gen-twirp_ruby"
|
33
|
-
end
|
34
|
-
````
|
35
|
-
|
36
|
-
Alternatively, install the gem on your system:
|
37
|
-
|
38
|
-
```bash
|
39
|
-
gem install protoc-gen-twirp_ruby
|
39
|
+
gem "protoc-gen-twirp_ruby", group: :development
|
40
40
|
```
|
41
41
|
|
42
|
-
|
42
|
+
If you previously used the Go version, see our [Migration Instructions](#migrating-from-the-go-module).
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
Pass `--twirp_ruby_out` to `protoc` to generate Twirp-Ruby code:
|
46
47
|
|
47
48
|
```bash
|
48
|
-
|
49
|
+
protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. ./path/to/service.proto
|
49
50
|
```
|
50
51
|
|
51
|
-
###
|
52
|
+
### Options
|
52
53
|
|
53
|
-
|
54
|
-
that might affect migration include:
|
54
|
+
You can configure the code generation. Pass options by specifying `--twirp_ruby_opt=<option>` on the `protoc` command line.
|
55
55
|
|
56
|
-
*
|
57
|
-
|
58
|
-
|
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.
|
59
61
|
|
60
|
-
|
62
|
+
Example :
|
63
|
+
|
64
|
+
```bash
|
65
|
+
protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. --twirp_ruby_opt=generate=client ./path/to/service.proto
|
66
|
+
```
|
61
67
|
|
62
|
-
|
68
|
+
## Migrating from the Go module
|
69
|
+
|
70
|
+
If you previously installed the `protoc-gen-twirp_ruby` Go module via the [Twirp-Ruby's Code Generation wiki page](https://github.com/arthurnn/twirp-ruby/wiki/Code-Generation)
|
71
|
+
instructions, then you'll want to uninstall it before invoking the `protoc` command.
|
63
72
|
|
64
73
|
```bash
|
65
|
-
|
74
|
+
rm `go env GOPATH`/bin/protoc-gen-twirp_ruby
|
66
75
|
```
|
67
76
|
|
68
|
-
###
|
77
|
+
### Differences from the Go module
|
69
78
|
|
70
|
-
|
71
|
-
|
79
|
+
This gem generates nearly identical Twirp-Ruby output as the Go version. Some notable differences
|
80
|
+
that might affect migration include:
|
72
81
|
|
73
|
-
*
|
74
|
-
|
75
|
-
* `
|
76
|
-
|
77
|
-
* `generate=client` - only generate `::Twirp::Client` subclass(es).
|
78
|
-
* `generate=both` - generate both services and clients. This is the default option to preserve
|
79
|
-
backwards compatibility.
|
82
|
+
* Generated output code is in [standardrb style](https://github.com/standardrb/standard).
|
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).
|
84
|
+
* Supports `ruby_package` in `.proto` files
|
85
|
+
* Supports protoc command line [configuration options](#options).
|
80
86
|
|
81
87
|
## Development
|
82
88
|
|
83
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.
|
84
90
|
|
85
|
-
|
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:
|
86
93
|
|
87
94
|
```bash
|
88
95
|
protoc --plugin=protoc-gen-twirp_ruby=./exe/protoc-gen-twirp_ruby --ruby_out=. --twirp_ruby_out=. ./example/hello_world.proto
|
89
96
|
```
|
90
97
|
|
91
|
-
|
98
|
+
Alternatively, install the local gem before invoking `protoc`:
|
92
99
|
|
93
100
|
```bash
|
94
101
|
bundle exec rake install
|
@@ -97,7 +104,16 @@ protoc --ruby_out=. --twirp_ruby_out=. ./example/hello_world.proto
|
|
97
104
|
|
98
105
|
## Releasing
|
99
106
|
|
100
|
-
|
107
|
+
Install the [GitHub CLI](https://cli.github.com): `brew install gh` or [follow the instructions](https://github.com/cli/cli#installation).
|
108
|
+
|
109
|
+
To release a new version:
|
110
|
+
|
111
|
+
* Submit a PR with the following changes (see e.g. [#30](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/30)):
|
112
|
+
* Update the version number in `version.rb`
|
113
|
+
* Update the CHANGELOG.md
|
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`.
|
101
117
|
|
102
118
|
## Contributing
|
103
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
|
@@ -27,13 +27,13 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
30
|
+
name: rake
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
|
-
type: :
|
36
|
+
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
@@ -41,7 +41,7 @@ dependencies:
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
44
|
+
name: rspec
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
|
-
name: rspec
|
58
|
+
name: rspec-file_fixtures
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
@@ -69,7 +69,7 @@ dependencies:
|
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
72
|
+
name: simplecov
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
75
|
- - ">="
|
@@ -96,7 +96,8 @@ dependencies:
|
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
-
description: A
|
99
|
+
description: A protoc plugin that generates Twirp-Ruby services and clients. A pure
|
100
|
+
Ruby alternative to the Go version that ships with Twirp-Ruby.
|
100
101
|
email: info@collectiveidea.com
|
101
102
|
executables:
|
102
103
|
- protoc-gen-twirp_ruby
|
@@ -116,6 +117,7 @@ files:
|
|
116
117
|
- lib/twirp/protoc_plugin/core_ext/string/camel_case.rb
|
117
118
|
- lib/twirp/protoc_plugin/core_ext/string/capitalize_first.rb
|
118
119
|
- lib/twirp/protoc_plugin/core_ext/string/snake_case.rb
|
120
|
+
- lib/twirp/protoc_plugin/core_ext/string/to_anchor.rb
|
119
121
|
- lib/twirp/protoc_plugin/descriptor_ext/file_descriptor_proto_ext.rb
|
120
122
|
- lib/twirp/protoc_plugin/descriptor_ext/service_descriptor_proto_ext.rb
|
121
123
|
- lib/twirp/protoc_plugin/process.rb
|
@@ -147,5 +149,5 @@ requirements: []
|
|
147
149
|
rubygems_version: 3.5.9
|
148
150
|
signing_key:
|
149
151
|
specification_version: 4
|
150
|
-
summary: A
|
152
|
+
summary: A protoc plugin for generating Twirp-Ruby clients and/or services
|
151
153
|
test_files: []
|