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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27c0b4bdc93f8fa61505a205af19a464e1c76537fba1e5dc920aa1fbae17b0d3
4
- data.tar.gz: f0f8c4030a7418df027cb23335f90bff71005329bd9ca4708db902a67ade1a51
3
+ metadata.gz: 72802f972933ce66eb55b4da8451ba00b2d12f0f52215a98c75af0d8016bdcfe
4
+ data.tar.gz: dc9c577f01084400fb2ab4db0150d5c06c384a840dbfe09ea8035686d3514f8c
5
5
  SHA512:
6
- metadata.gz: 8077c5f026c6e8f945f0a522e260bb65a7fcc49a5e37d37dda3c0d08703d645ca32c2929579586ac52e9dbbb14f8eecda86dfb3d4005a9ab685978f93643dee2
7
- data.tar.gz: 90f9cbd36f60285beefa99a540ae747dfd336939ef66fcba19d3eb32f25e8b4b74a4b15b2082d33395dfc2c6ee1555d7972d79fc9c7a0aa4acd98f55a38b8bd9
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: Ruby
1
+ name: Specs
2
2
 
3
- on: [push,pull_request]
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: Run the default task
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
+ [![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
- - loads any `_twirp.rb` files may exist within any folder of your app's `lib` directory
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 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);
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
- format.pb do
97
- render plain: YourProtoResponse.to_proto
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
@@ -9,4 +9,4 @@ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
12
- task default: %i[spec rubocop]
12
+ task default: :spec
data/docker-compose.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  services:
2
2
  bundle: &bundle
3
- env_file: .env
4
3
  stdin_open: true
5
4
  tty: true
6
5
  build: .
@@ -15,7 +15,7 @@ module RailsRespondToPb
15
15
  end
16
16
 
17
17
  initializer 'respond_to_pb.require_pb' do
18
- Dir["#{Rails.root}/lib/**/*_twirp.rb"].each { |file| require file }
18
+ Dir["#{Rails.root}/lib/**/*_twirp.rb"].sort.each { |file| require file }
19
19
  end
20
20
  end
21
21
  end
@@ -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
- ::ActiveSupport::Dependencies.constantize("#{@resource}Service")
37
+ "#{@resource}Service".constantize
37
38
  end
38
39
 
39
40
  def controller_class
40
- ::ActiveSupport::Dependencies.constantize("#{@resource}Controller")
41
+ "#{@resource}Controller".constantize
41
42
  end
42
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsRespondToPb
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -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('>= 3.0.0')
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.3
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: 2021-08-18 00:00:00.000000000 Z
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/main.yml"
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: 3.0.0
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.2.25
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