rails_respond_to_pb 0.1.1 → 0.1.2

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: b6aead0d00f97d47b6b8131b96ba6aed319349e8f12c9b3ac5eeddc1a75becfa
4
- data.tar.gz: 7d2a51d4f9b722b9143e74c7796a89f0de75e7211a42b6b5f356745ddf5c23f2
3
+ metadata.gz: dfaac3cf5080bc47d884e92e4fa12da3512490396c1e40fed79172667a645527
4
+ data.tar.gz: 7570d05d12f924e6498c7497d7e0bae2133fb6d95a652ea6c64a81797db4cbe7
5
5
  SHA512:
6
- metadata.gz: 6e266a4185a7d352ae3dd8c1c20f0edb6eb5b92911d72bce0fc98eca995dd9bbfd74dd29c9de82297a2b1e4a89ceb7733779c911bd7f31f6ec15e41ddcf526cc
7
- data.tar.gz: bba14ac758f6cdcde1ba40d1f48edac8b193c1ad481340f0dd96ddf2faf67f664aba61a7fa5b1666b2fff9cd6f117275c9638742d655ab845a34d1eac4d724a6
6
+ metadata.gz: 43ab9bf02f8652bec55b073532c6ec06d5fc45a8c7c5668832c5644874f4d977a2e4294fd47b2db516dabd10f303b4efdccaa7faff7d8e64be294a7b5338034a
7
+ data.tar.gz: a5e70fb72e256eca9558e2f7a19b1213da54f9daf5df680c7d7e51353241fbd688fd19c5e0e02b8723f22bee055f8633b3f03a2d01833c6136a94643f614f374
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.1
8
+ ## 0.1.2
9
9
 
10
10
  - In the beginning...
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # RailsRespondToPb
1
+ # rails_respond_to_pb
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_respond_to_pb`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This gem allows you to route RPC calls via protobuf to an existing rails controller. Currently supporting:
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ - [Twirp](https://github.com/twitchtv/twirp-ruby)
6
6
 
7
7
  ## Installation
8
8
 
@@ -14,25 +14,138 @@ gem 'rails_respond_to_pb'
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle install
17
+ ```sh
18
+ bundle install
19
+ ```
18
20
 
19
21
  Or install it yourself as:
20
22
 
21
- $ gem install rails_respond_to_pb
23
+ ```sh
24
+ gem install rails_respond_to_pb
25
+ ```
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ This gem loads Rails middleware that routes to services with Controllers as Handlers.
30
+
31
+ - assumes a single `ThingsService` per controller
32
+ - Typical Rails namey-ness conventions are followed here
33
+ - assumes a `ThingsService` routes to a `ThingsController`
34
+ - loads any `_twirp.rb` files may exist within any folder of your app's `lib` directory
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').proto`
37
+ - looking into `render pb:`
38
+
39
+ Generate a proto like this for each of your controllers (`rpc` methods should match your controller methods. `message` is to your discretion):
40
+
41
+ ```proto
42
+ syntax = "proto3";
43
+
44
+ service Things {
45
+ // these rpc methods are important - use what's in the corresponding ThingsController.
46
+ // whatever is sent as an argument will be made available to the controller as `params`
47
+ rpc create (ThingParams) returns (ThingResponse);
48
+ rpc show (ThingParams) returns (ThingResponse);
49
+ rpc index (ThingFilter) returns (ThingList);
50
+ rpc update (ThingParams) returns (ThingResponse);
51
+ rpc destroy (ThingParams) returns (ThingResponse);
52
+ }
53
+
54
+ message ThingParams {
55
+ int32 id = 1;
56
+ string name = 2;
57
+ }
58
+
59
+ message ThingFilter {
60
+ string name = 1;
61
+ }
62
+
63
+ message ThingResponse {
64
+ int32 id = 1;
65
+ string name = 2;
66
+ }
67
+
68
+ message ThingList {
69
+ repeated ThingResponse things = 1;
70
+ }
71
+ ```
72
+
73
+ ### Server
74
+
75
+ This gem will allow your app to respond to Twirp requests. No setup required, other than having the prerequisite Service files loaded in your application.
76
+
77
+ ### Client
78
+
79
+ Assuming you have the prerequisite Client files loaded in your application, you can connect to a Twirp server
80
+
81
+ ```ruby
82
+ client = ThingsClient.new('http://localhost:3000')
83
+ query = ThingFilter.new name: 'foo'
84
+ client.index(query)
85
+ ```
86
+
87
+ ### Building protos
88
+
89
+ For inspiration on how to build proto files locally (and working with docker-compose), here are some services to use within your application:
90
+
91
+ ```yaml
92
+ services:
93
+ bundle: &bundle # run your typical bundle commands
94
+ env_file: .env
95
+ stdin_open: true
96
+ tty: true
97
+ build: .
98
+ entrypoint: bundle
99
+ command: check
100
+ volumes:
101
+ - .:/usr/src/app:delegated # hot reload your application's code
102
+ - bundle:/usr/local/bundle:delegated # cache bundle installs
103
+ - ~/Projects:/local # used to install gems locally rename ~/Projects to whichever dir your code lives in
104
+
105
+ rspec: # run your tests!!
106
+ <<: *bundle
107
+ entrypoint: bundle exec rspec
108
+ command: --version
109
+
110
+ protoc: # generate code from proto files
111
+ build: .
112
+ entrypoint: bundle
113
+ command: |
114
+ exec grpc_tools_ruby_protoc
115
+ -I ./lib/protos --ruby_out=./lib/protobuf --twirp_ruby_out=./lib/protobuf
116
+ ./lib/protos/things.proto
117
+ volumes:
118
+ - .:/usr/src/app:delegated
119
+ - bundle:/usr/local/bundle:delegated
120
+ ```
121
+
122
+ The `twirp_ruby_out` function needs to be made available to your environment. Use a multistage file, like so:
123
+
124
+ ```dockerfile
125
+ FROM golang:1 AS go
126
+ RUN go get github.com/twitchtv/twirp-ruby/protoc-gen-twirp_ruby
127
+
128
+ # or whatever version of ruby you're using
129
+ FROM ruby:3
130
+ # Install necessary executable to build protos
131
+ COPY --from=go /go/bin /usr/local/bin
132
+ ```
26
133
 
27
134
  ## Development
28
135
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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.
30
143
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. 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).
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).
32
145
 
33
146
  ## Contributing
34
147
 
35
- Bug reports and pull requests are welcome on GitHub at 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/master/CODE_OF_CONDUCT.md).
148
+ 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).
36
149
 
37
150
  ## License
38
151
 
@@ -40,4 +153,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
153
 
41
154
  ## Code of Conduct
42
155
 
43
- Everyone interacting in the RailsRespondToPb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails_respond_to_pb/blob/master/CODE_OF_CONDUCT.md).
156
+ Everyone interacting in the RailsRespondToPb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails_respond_to_pb/blob/main/CODE_OF_CONDUCT.md).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsRespondToPb
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -29,7 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
+ spec.add_runtime_dependency 'grpc-tools', '~> 1.38'
32
33
  spec.add_runtime_dependency 'rails', ENV['RAILS_VERSION'] || '>= 6'
34
+ spec.add_runtime_dependency 'twirp', '~> 1.7'
33
35
 
34
36
  # For more information and examples about making a new gem, checkout our
35
37
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_respond_to_pb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett C. Dudo
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2021-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grpc-tools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.38'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.38'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: twirp
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
27
55
  description: Middleware for a Rails App providing functionality for gRPC and Twirp
28
56
  email:
29
57
  - brett@dudo.io