rails_respond_to_pb 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +41 -0
- data/.github/workflows/rubocop.yml +20 -0
- data/.github/workflows/{main.yml → spec.yml} +6 -4
- data/CHANGELOG.md +7 -0
- data/README.md +32 -20
- data/Rakefile +1 -1
- data/docker-compose.yml +0 -1
- data/lib/rails_respond_to_pb/railtie.rb +1 -1
- data/lib/rails_respond_to_pb/respond_to_pb.rb +3 -2
- data/lib/rails_respond_to_pb/version.rb +1 -1
- data/rails_respond_to_pb.gemspec +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72802f972933ce66eb55b4da8451ba00b2d12f0f52215a98c75af0d8016bdcfe
|
4
|
+
data.tar.gz: dc9c577f01084400fb2ab4db0150d5c06c384a840dbfe09ea8035686d3514f8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 413ee918b3c2412990c7c15e37d25aa072c7857dd56ecdabe167f7ab0e2e2a864990e3af5ccad6d81a60a054d657fdb18f77042e9153991f9d083f16b121b20b
|
7
|
+
data.tar.gz: 75fef258b0b4386cf5e8220dabe2407b8ce51cfdae8275ead38754f0efc3b4341951ef80a1fd21ccd35be7c64f99e315998c19d2b9adc4b4b21c38cb986c25c8
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: release
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
release-please:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- name: Set ENV
|
13
|
+
run: |
|
14
|
+
echo INPUT_PACKAGE_NAME=${GITHUB_REPOSITORY##*/} >> $GITHUB_ENV
|
15
|
+
echo INPUT_VERSION_FILE=lib/${GITHUB_REPOSITORY##*/}/version.rb >> $GITHUB_ENV
|
16
|
+
- uses: GoogleCloudPlatform/release-please-action@v2
|
17
|
+
id: release
|
18
|
+
with:
|
19
|
+
release-type: ruby
|
20
|
+
package-name: ${{ env.INPUT_PACKAGE_NAME }}
|
21
|
+
bump-minor-pre-major: true
|
22
|
+
version-file: ${{ env.INPUT_VERSION_FILE }}
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
if: ${{ steps.release.outputs.release_created }}
|
25
|
+
- uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: 3.0.0
|
28
|
+
if: ${{ steps.release.outputs.release_created }}
|
29
|
+
- run: bundle install
|
30
|
+
if: ${{ steps.release.outputs.release_created }}
|
31
|
+
- name: publish gem
|
32
|
+
run: |
|
33
|
+
mkdir -p $HOME/.gem
|
34
|
+
touch $HOME/.gem/credentials
|
35
|
+
chmod 0600 $HOME/.gem/credentials
|
36
|
+
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
37
|
+
gem build *.gemspec
|
38
|
+
gem push *.gem
|
39
|
+
env:
|
40
|
+
RUBYGEMS_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
|
41
|
+
if: ${{ steps.release.outputs.release_created }}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Rubocop
|
2
|
+
|
3
|
+
on:
|
4
|
+
- push
|
5
|
+
- pull_request
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby
|
13
|
+
uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 3.0.0
|
16
|
+
- name: Rubocop
|
17
|
+
run: |
|
18
|
+
gem install bundler -v 2.2.3
|
19
|
+
bundle install
|
20
|
+
bundle exec rake rubocop
|
@@ -1,6 +1,8 @@
|
|
1
|
-
name:
|
1
|
+
name: Specs
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
- push
|
5
|
+
- pull_request
|
4
6
|
|
5
7
|
jobs:
|
6
8
|
build:
|
@@ -11,8 +13,8 @@ jobs:
|
|
11
13
|
uses: ruby/setup-ruby@v1
|
12
14
|
with:
|
13
15
|
ruby-version: 3.0.0
|
14
|
-
- name:
|
16
|
+
- name: Spec
|
15
17
|
run: |
|
16
18
|
gem install bundler -v 2.2.3
|
17
19
|
bundle install
|
18
|
-
bundle exec rake
|
20
|
+
bundle exec rake spec
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.2.0](https://www.github.com/dudo/rails_respond_to_pb/compare/v0.1.5...v0.2.0) (2021-12-22)
|
9
|
+
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
* automate releases ([f880b17](https://www.github.com/dudo/rails_respond_to_pb/commit/f880b17fca29f70d9ca275f9c16316c31cd752f2))
|
14
|
+
|
8
15
|
## 0.1.3
|
9
16
|
|
10
17
|
- In the beginning...
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# rails_respond_to_pb
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/rails_respond_to_pb)
|
4
|
+
|
3
5
|
This gem allows you to route RPC calls via protobuf to an existing rails controller. Currently supporting:
|
4
6
|
|
5
7
|
- [Twirp](https://github.com/twitchtv/twirp-ruby)
|
@@ -31,7 +33,8 @@ This gem loads Rails middleware that routes to services with Controllers as Hand
|
|
31
33
|
- assumes a single `ThingsService` per controller
|
32
34
|
- Typical Rails namey-ness conventions are followed here
|
33
35
|
- assumes a `ThingsService` routes to a `ThingsController`
|
34
|
-
-
|
36
|
+
- looking into building generating proto files from controllers
|
37
|
+
- loads any `_twirp.rb` files that exist within your app's `lib` directory
|
35
38
|
- allows a controller to `respond_to` the `pb` format
|
36
39
|
- currently you'd respond with a `render plain: ThingResponse.new(id: 1, name: 'Foo').to_proto`
|
37
40
|
- looking into `render pb:`
|
@@ -44,11 +47,11 @@ syntax = "proto3";
|
|
44
47
|
service Things {
|
45
48
|
// these rpc methods are important - use what's in the corresponding ThingsController.
|
46
49
|
// whatever is sent as an argument will be made available to the controller as `params`
|
47
|
-
rpc
|
48
|
-
rpc
|
49
|
-
rpc
|
50
|
-
rpc
|
51
|
-
rpc
|
50
|
+
rpc Create (ThingParams) returns (ThingResponse);
|
51
|
+
rpc Show (ThingParams) returns (ThingResponse);
|
52
|
+
rpc Index (ThingFilter) returns (ThingList);
|
53
|
+
rpc Update (ThingParams) returns (ThingResponse);
|
54
|
+
rpc Destroy (ThingParams) returns (ThingResponse);
|
52
55
|
}
|
53
56
|
|
54
57
|
message ThingParams {
|
@@ -93,8 +96,17 @@ The **required** setup here is:
|
|
93
96
|
|
94
97
|
```ruby
|
95
98
|
respond_to do |format|
|
96
|
-
|
97
|
-
|
99
|
+
format.pb do
|
100
|
+
render plain: YourProtoResponse.to_proto
|
101
|
+
```
|
102
|
+
|
103
|
+
Of note, if you're trying to wire up **entirely new** methods, you do **NOT** need this gem at all, and you can simply add this to your routes file:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
handler = ThingsHandler.new()
|
107
|
+
service = ThingsService.new(handler)
|
108
|
+
|
109
|
+
mount service, at: service.full_name
|
98
110
|
```
|
99
111
|
|
100
112
|
### Client
|
@@ -107,6 +119,18 @@ query = ThingFilter.new name: 'foo'
|
|
107
119
|
client.index(query)
|
108
120
|
```
|
109
121
|
|
122
|
+
## Development
|
123
|
+
|
124
|
+
I typically add an alias to make working with dockerized apps easier. This assumes [docker](https://docs.docker.com/get-docker/) is running.
|
125
|
+
|
126
|
+
```sh
|
127
|
+
alias dr="docker compose run --rm "
|
128
|
+
```
|
129
|
+
|
130
|
+
After checking out the repo, run `dr bundle install` to spin up a container, and install dependencies. Then, run `dr rspec spec` to run the tests. You can also run `dr bundle console` for an interactive prompt that will allow you to experiment.
|
131
|
+
|
132
|
+
To release a new version, update the version number in `version.rb`, and then run `dr 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).
|
133
|
+
|
110
134
|
### Building protos
|
111
135
|
|
112
136
|
For inspiration on how to build proto files locally (and working with docker-compose), here are some services to use within your application:
|
@@ -154,18 +178,6 @@ FROM ruby:3
|
|
154
178
|
COPY --from=go /go/bin /usr/local/bin
|
155
179
|
```
|
156
180
|
|
157
|
-
## Development
|
158
|
-
|
159
|
-
I typically add an alias to make working with dockerized apps easier. This assumes [docker](https://docs.docker.com/get-docker/) is running.
|
160
|
-
|
161
|
-
```sh
|
162
|
-
alias dr="docker compose run --rm "
|
163
|
-
```
|
164
|
-
|
165
|
-
After checking out the repo, run `dr bundle install` to spin up a container, and install dependencies. Then, run `dr rspec spec` to run the tests. You can also run `dr bundle console` for an interactive prompt that will allow you to experiment.
|
166
|
-
|
167
|
-
To release a new version, update the version number in `version.rb`, and then run `dr 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).
|
168
|
-
|
169
181
|
## Contributing
|
170
182
|
|
171
183
|
Bug reports and pull requests are welcome on [GitHub](https://github.com/[USERNAME]/rails_respond_to_pb). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rails_respond_to_pb/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/docker-compose.yml
CHANGED
@@ -9,6 +9,7 @@ class RespondToPb
|
|
9
9
|
|
10
10
|
def call(env)
|
11
11
|
_, @resource, @action = env['PATH_INFO'].split('/')
|
12
|
+
@resource = @resource.split('.').map(&:camelize).join('::')
|
12
13
|
|
13
14
|
if env['CONTENT_TYPE'] == Twirp::Encoding::PROTO
|
14
15
|
env['HTTP_ACCEPT'] = Twirp::Encoding::PROTO
|
@@ -33,10 +34,10 @@ class RespondToPb
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def service_class
|
36
|
-
|
37
|
+
"#{@resource}Service".constantize
|
37
38
|
end
|
38
39
|
|
39
40
|
def controller_class
|
40
|
-
|
41
|
+
"#{@resource}Controller".constantize
|
41
42
|
end
|
42
43
|
end
|
data/rails_respond_to_pb.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = 'Middleware for a Rails App providing functionality for gRPC and Twirp'
|
13
13
|
spec.homepage = 'https://github.com/dudo/rails_respond_to_pb'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new('>=
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7')
|
16
16
|
|
17
17
|
# spec.metadata['allowed_push_host'] = 'http://mygemserver.com'
|
18
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_respond_to_pb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett C. Dudo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc-tools
|
@@ -59,7 +59,9 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".github/workflows/
|
62
|
+
- ".github/workflows/release.yml"
|
63
|
+
- ".github/workflows/rubocop.yml"
|
64
|
+
- ".github/workflows/spec.yml"
|
63
65
|
- ".gitignore"
|
64
66
|
- ".rspec"
|
65
67
|
- ".rubocop.yml"
|
@@ -95,14 +97,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
97
|
requirements:
|
96
98
|
- - ">="
|
97
99
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
100
|
+
version: '2.7'
|
99
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
102
|
requirements:
|
101
103
|
- - ">="
|
102
104
|
- !ruby/object:Gem::Version
|
103
105
|
version: '0'
|
104
106
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
107
|
+
rubygems_version: 3.3.7
|
106
108
|
signing_key:
|
107
109
|
specification_version: 4
|
108
110
|
summary: Middleware for a Rails App providing functionality for gRPC and Twirp
|