rails_respond_to_pb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/README.md +27 -4
- data/docker-compose.yml +4 -0
- data/lib/rails_respond_to_pb/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c0b4bdc93f8fa61505a205af19a464e1c76537fba1e5dc920aa1fbae17b0d3
|
4
|
+
data.tar.gz: f0f8c4030a7418df027cb23335f90bff71005329bd9ca4708db902a67ade1a51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8077c5f026c6e8f945f0a522e260bb65a7fcc49a5e37d37dda3c0d08703d645ca32c2929579586ac52e9dbbb14f8eecda86dfb3d4005a9ab685978f93643dee2
|
7
|
+
data.tar.gz: 90f9cbd36f60285beefa99a540ae747dfd336939ef66fcba19d3eb32f25e8b4b74a4b15b2082d33395dfc2c6ee1555d7972d79fc9c7a0aa4acd98f55a38b8bd9
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,6 @@ 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.
|
8
|
+
## 0.1.3
|
9
9
|
|
10
10
|
- In the beginning...
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ This gem loads Rails middleware that routes to services with Controllers as Hand
|
|
33
33
|
- assumes a `ThingsService` routes to a `ThingsController`
|
34
34
|
- loads any `_twirp.rb` files may exist within any folder of your app's `lib` directory
|
35
35
|
- allows a controller to `respond_to` the `pb` format
|
36
|
-
- currently you'd respond with a `render plain: ThingResponse.new(id: 1, name: 'Foo').
|
36
|
+
- currently you'd respond with a `render plain: ThingResponse.new(id: 1, name: 'Foo').to_proto`
|
37
37
|
- looking into `render pb:`
|
38
38
|
|
39
39
|
Generate a proto like this for each of your controllers (`rpc` methods should match your controller methods. `message` is to your discretion):
|
@@ -72,11 +72,34 @@ message ThingList {
|
|
72
72
|
|
73
73
|
### Server
|
74
74
|
|
75
|
-
This gem will allow your app to respond to Twirp requests.
|
75
|
+
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.
|
76
|
+
|
77
|
+
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:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
def index
|
81
|
+
# ... business as usual
|
82
|
+
|
83
|
+
respond_to do |format|
|
84
|
+
format.pb do
|
85
|
+
render plain: ThingList.new(things: Thing.all.map { |r| ThingResponse.new(r.as_json) }).to_proto
|
86
|
+
end
|
87
|
+
format.json { render: Thing.all.as_json } # or whatever your controller responds to usually
|
88
|
+
end
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
The **required** setup here is:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
respond_to do |format|
|
96
|
+
format.pb do
|
97
|
+
render plain: YourProtoResponse.to_proto
|
98
|
+
```
|
76
99
|
|
77
100
|
### Client
|
78
101
|
|
79
|
-
Assuming you have the prerequisite Client files loaded in your application, you can connect to a Twirp server
|
102
|
+
Assuming you have the prerequisite Client files loaded in your application, you can connect to a Twirp server as usual:
|
80
103
|
|
81
104
|
```ruby
|
82
105
|
client = ThingsClient.new('http://localhost:3000')
|
@@ -139,7 +162,7 @@ I typically add an alias to make working with dockerized apps easier. This assum
|
|
139
162
|
alias dr="docker compose run --rm "
|
140
163
|
```
|
141
164
|
|
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
|
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.
|
143
166
|
|
144
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).
|
145
168
|
|
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
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
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.3
|
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
11
|
date: 2021-08-18 00:00:00.000000000 Z
|
@@ -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
|
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
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.25
|
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: []
|