rails_respond_to_pb 0.1.2 → 0.2.0
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/CHANGELOG.md +8 -1
- data/README.md +56 -21
- data/docker-compose.yml +4 -0
- data/lib/rails_respond_to_pb/respond_to_pb.rb +2 -2
- data/lib/rails_respond_to_pb/version.rb +1 -1
- data/rails_respond_to_pb.gemspec +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aa245e7ea71430e7649f6287293c9c2e1daafec5ff1689c5c78ba78f9bb9baf
|
4
|
+
data.tar.gz: 24f3a9834c934dc896b772780275a82a9f49094951cc8da185547fc98be05f16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 625454f9b1c30231ce95c46460f6723b283d05a1f1664dfff20906ed49888b927db1fca70f992d31d7974a17883b99e43fc32ecfee057b857425731f79af7a85
|
7
|
+
data.tar.gz: 4c8f924f845479b6eaf938f50de51fe2ecc375af260ad36886fc92c6b82a1c10a5b84a037d1b8bcdfd5197c40d38744a353cb065b9cb24a724e9202c4080e036
|
@@ -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 }}
|
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.1.2
|
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
|
+
|
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,9 +33,10 @@ 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
|
-
- currently you'd respond with a `render plain: ThingResponse.new(id: 1, name: 'Foo').
|
39
|
+
- currently you'd respond with a `render plain: ThingResponse.new(id: 1, name: 'Foo').to_proto`
|
37
40
|
- looking into `render pb:`
|
38
41
|
|
39
42
|
Generate a proto like this for each of your controllers (`rpc` methods should match your controller methods. `message` is to your discretion):
|
@@ -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 {
|
@@ -72,11 +75,43 @@ message ThingList {
|
|
72
75
|
|
73
76
|
### Server
|
74
77
|
|
75
|
-
This gem will allow your app to respond to Twirp requests.
|
78
|
+
This gem will allow your app to respond to Twirp requests. There is little setup required, other than having the prerequisite Service files loaded in your application.
|
79
|
+
|
80
|
+
Given a Service file of `ThingsService`, this gem assumes the presence of a `ThingsController` with actions corresponding with `rpc` methods. To allow your controller to respond to the RPC request, simply update the action accordingly:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
def index
|
84
|
+
# ... business as usual
|
85
|
+
|
86
|
+
respond_to do |format|
|
87
|
+
format.pb do
|
88
|
+
render plain: ThingList.new(things: Thing.all.map { |r| ThingResponse.new(r.as_json) }).to_proto
|
89
|
+
end
|
90
|
+
format.json { render: Thing.all.as_json } # or whatever your controller responds to usually
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
The **required** setup here is:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
respond_to do |format|
|
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
|
110
|
+
```
|
76
111
|
|
77
112
|
### Client
|
78
113
|
|
79
|
-
Assuming you have the prerequisite Client files loaded in your application, you can connect to a Twirp server
|
114
|
+
Assuming you have the prerequisite Client files loaded in your application, you can connect to a Twirp server as usual:
|
80
115
|
|
81
116
|
```ruby
|
82
117
|
client = ThingsClient.new('http://localhost:3000')
|
@@ -84,6 +119,18 @@ query = ThingFilter.new name: 'foo'
|
|
84
119
|
client.index(query)
|
85
120
|
```
|
86
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
|
+
|
87
134
|
### Building protos
|
88
135
|
|
89
136
|
For inspiration on how to build proto files locally (and working with docker-compose), here are some services to use within your application:
|
@@ -131,18 +178,6 @@ FROM ruby:3
|
|
131
178
|
COPY --from=go /go/bin /usr/local/bin
|
132
179
|
```
|
133
180
|
|
134
|
-
## Development
|
135
|
-
|
136
|
-
I typically add an alias to make working with dockerized apps easier. This assumes [docker](https://docs.docker.com/get-docker/) is running.
|
137
|
-
|
138
|
-
```sh
|
139
|
-
alias dr="docker compose run --rm "
|
140
|
-
```
|
141
|
-
|
142
|
-
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 exec console` for an interactive prompt that will allow you to experiment.
|
143
|
-
|
144
|
-
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).
|
145
|
-
|
146
181
|
## Contributing
|
147
182
|
|
148
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/docker-compose.yml
CHANGED
@@ -9,6 +9,10 @@ services:
|
|
9
9
|
volumes:
|
10
10
|
- .:/usr/src/gem:delegated
|
11
11
|
- bundle:/usr/local/bundle:delegated
|
12
|
+
- ~/.gitconfig:/etc/gitconfig:ro
|
13
|
+
- ~/.ssh:/root/.ssh:ro
|
14
|
+
- ~/.gemrc:/etc/.gemrc:ro
|
15
|
+
- ~/.local/share/gem/credentials:/root/.local/share/gem/credentials:ro
|
12
16
|
|
13
17
|
rspec:
|
14
18
|
<<: *bundle
|
@@ -33,10 +33,10 @@ class RespondToPb
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def service_class
|
36
|
-
|
36
|
+
"#{@resource}Service".constantize
|
37
37
|
end
|
38
38
|
|
39
39
|
def controller_class
|
40
|
-
|
40
|
+
"#{@resource}Controller".constantize
|
41
41
|
end
|
42
42
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett C. Dudo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc-tools
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".github/workflows/main.yml"
|
63
|
+
- ".github/workflows/release.yml"
|
63
64
|
- ".gitignore"
|
64
65
|
- ".rspec"
|
65
66
|
- ".rubocop.yml"
|
@@ -87,7 +88,7 @@ metadata:
|
|
87
88
|
homepage_uri: https://github.com/dudo/rails_respond_to_pb
|
88
89
|
source_code_uri: https://github.com/dudo/rails_respond_to_pb
|
89
90
|
changelog_uri: https://github.com/dudo/rails_respond_to_pb/blob/main/CHANGELOG.md
|
90
|
-
post_install_message:
|
91
|
+
post_install_message:
|
91
92
|
rdoc_options: []
|
92
93
|
require_paths:
|
93
94
|
- lib
|
@@ -95,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
96
|
requirements:
|
96
97
|
- - ">="
|
97
98
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
99
|
+
version: '2.7'
|
99
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
101
|
requirements:
|
101
102
|
- - ">="
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
version: '0'
|
104
105
|
requirements: []
|
105
106
|
rubygems_version: 3.2.3
|
106
|
-
signing_key:
|
107
|
+
signing_key:
|
107
108
|
specification_version: 4
|
108
109
|
summary: Middleware for a Rails App providing functionality for gRPC and Twirp
|
109
110
|
test_files: []
|