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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30f68aaf9f4bab30eb440d98f94cb4840712d18ce8dd44b846b1ba2b8c95878f
4
- data.tar.gz: c6ca8284ee938254b60383cf3c38bb801940f758e460c0fd63cdf61468d0f9e1
3
+ metadata.gz: dae48985eff8d4e3133f64234bf45aa141297f9b8f5e0d516f6ff6c7f9e88d11
4
+ data.tar.gz: 8feef99527f54ccae5a134e69a5d8f175afa638666fd7664b468ad65a8162347
5
5
  SHA512:
6
- metadata.gz: 55d98147c37865e774a5e5b68206b53fad68c25b7ac61a9a69a92bf09d0adb569a7e8175aae8dd281be1b94099b699a7830f18c7c256e78db00799b5cddb092b
7
- data.tar.gz: b32badee47a22d048aef598801a4412e8cd85b5cc69d6f1665f88cb58fd0d3d7a0adca19145713a258529e480bef58cc5f98d14792f1b9c4e42d36c3c6d280b5
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
- - Nothing (yet)
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
- [![Build](https://github.com/collectiveidea/protoc-gen-twirp_ruby/actions/workflows/main.yml/badge.svg)](https://github.com/collectiveidea/protoc-gen-twirp_ruby/actions/workflows/main.yml)
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 provides a `protoc` plugin that generates [Twirp-Ruby](https://github.com/arthurnn/twirp-ruby) services and clients.
8
+ This gem is a `protoc` plugin that generates [Twirp-Ruby](https://github.com/arthurnn/twirp-ruby) services and clients.
8
9
 
9
- **NOTE:** Twirp-Ruby [already has a protoc plugin available](https://github.com/arthurnn/twirp-ruby/tree/main/protoc-gen-twirp_ruby)
10
- released as a `go` module. This project creates an alternative plugin written in Ruby and distributed as a gem that
11
- produces comparable output while being both more familiar and accessible to Ruby developers.
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
- Install the gem by adding it to your Gemfile:
36
+ Run `gem install protoc-gen-twirp_ruby` or add it to your Gemfile:
29
37
 
30
38
  ```ruby
31
- group :development, :test do
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
- ## Migration from the `protoc-gen-twirp_ruby` go module
42
+ If you previously used the Go version, see our [Migration Instructions](#migrating-from-the-go-module).
43
43
 
44
- If you have previously installed the `go` version of the plugin via the [Twirp-Ruby Code Generation wiki page](https://github.com/arthurnn/twirp-ruby/wiki/Code-Generation)
45
- instructions, then you'll want to uninstall it before invoking the `protoc` command.
44
+ ## Usage
45
+
46
+ Pass `--twirp_ruby_out` to `protoc` to generate Twirp-Ruby code:
46
47
 
47
48
  ```bash
48
- rm `go env GOPATH`/bin/protoc-gen-twirp_ruby
49
+ protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. ./path/to/service.proto
49
50
  ```
50
51
 
51
- ### Notable plugin differences
52
+ ### Options
52
53
 
53
- This gem generates nearly identical Twirp-Ruby output as the go version plugin. Some notable differences
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
- * Generated output code is in [standardrb style](https://github.com/standardrb/standard).
57
- * 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).
58
- * Supports various protoc command line [configuration options](https://github.com/collectiveidea/protoc-gen-twirp_ruby?tab=readme-ov-file#options).
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
- ## Usage
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
- Once `protoc` and the `protoc-gen-twirp_ruby` gem is installed, pass `--twirp_ruby_out` to generate Twirp-Ruby code:
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
- protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. ./path/to/service.proto
74
+ rm `go env GOPATH`/bin/protoc-gen-twirp_ruby
66
75
  ```
67
76
 
68
- ### Options
77
+ ### Differences from the Go module
69
78
 
70
- The plugin supports the following options to configure code generation. Pass options by
71
- specifying `--twirp_ruby_opt=<option>` on the `protoc` command line.
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
- * `skip-empty`: Avoid generating a `_twirp.rb` for a `.proto` with no service definitions. By default, a `_twirp.rb`
74
- file is generated for every proto file listed on the command line, even if the file is empty scaffolding.
75
- * `generate=<service|client|both>`: Customize generated output to include generated services, clients, or both.
76
- * `generate=service` - only generate `::Twirp::Service` subclass(es).
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
- For continued development purposes, we can route `protoc` to the local repo code for the plugin and generate against the example via:
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
- The local code for the gem can also be installed via `bundle exec rake install` to omit the `--plugin=protoc-gen-twirp_ruby=` option from `protoc`:
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
- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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 => Boolean, 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 if options[:skip_empty] && !proto_file.has_service?
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 "skip-empty" flag.
46
- # @return [Hash{Symbol => Boolean, Symbol}]
47
- # * :skip_empty [Boolean] indicating whether generation should skip creating a twirp file
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 == "skip-empty"
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Twirp
4
4
  module ProtocPlugin
5
- VERSION = "1.1.0"
5
+ VERSION = "1.2.0"
6
6
  end
7
7
  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.1.0
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-21 00:00:00.000000000 Z
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: racc
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: :runtime
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: rake
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: rspec-file_fixtures
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 Ruby protoc plugin generator for Twirp-Ruby.
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 Ruby protoc plugin generator for Twirp-Ruby.
152
+ summary: A protoc plugin for generating Twirp-Ruby clients and/or services
151
153
  test_files: []