rails_respond_to_pb 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -18
- data/lib/rails_respond_to_pb/version.rb +1 -1
- data/rails_respond_to_pb.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c322c035c9d8609dc8627e797c78c18a180646114ca046e712de5c602833471
|
4
|
+
data.tar.gz: 4620238b1f729bf8afff9f914e89c66d2f28fd19527012bbbd292302cd5da68d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e46f10d9b60f0670413af3683d9ef4ad72d6f84ac1e7773d2bb690ac8e62273e8f48d4de3bd0dc8db2296c7a2eb661d2380945f1a3dec45fa4408392da4a7a8
|
7
|
+
data.tar.gz: 7888edb96143bba2691b486e81368bf3917d20ddd1c6fe66a47b2d7f388fe6b0c3808d01cbeafdcfe2ee7e97bc0e0ab72ab59e20759b049f0ac10cc6ad2d306a
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# rails_respond_to_pb
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rails_respond_to_pb.svg)](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 {
|
@@ -97,6 +100,15 @@ respond_to do |format|
|
|
97
100
|
render plain: YourProtoResponse.to_proto
|
98
101
|
```
|
99
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
|
+
```
|
111
|
+
|
100
112
|
### Client
|
101
113
|
|
102
114
|
Assuming you have the prerequisite Client files loaded in your application, you can connect to a Twirp server as usual:
|
@@ -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/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.1.4
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc-tools
|
@@ -87,7 +87,7 @@ metadata:
|
|
87
87
|
homepage_uri: https://github.com/dudo/rails_respond_to_pb
|
88
88
|
source_code_uri: https://github.com/dudo/rails_respond_to_pb
|
89
89
|
changelog_uri: https://github.com/dudo/rails_respond_to_pb/blob/main/CHANGELOG.md
|
90
|
-
post_install_message:
|
90
|
+
post_install_message:
|
91
91
|
rdoc_options: []
|
92
92
|
require_paths:
|
93
93
|
- lib
|
@@ -95,15 +95,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
95
|
requirements:
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
98
|
+
version: '2.7'
|
99
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
rubygems_version: 3.2.
|
106
|
-
signing_key:
|
105
|
+
rubygems_version: 3.2.32
|
106
|
+
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Middleware for a Rails App providing functionality for gRPC and Twirp
|
109
109
|
test_files: []
|