rails_twirp 0.7.1 → 0.9.1

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: '08d0f51ad8a5b177a88a6c83db754f4c067257116494bc0d271ee2868c59f8d2'
4
- data.tar.gz: 8dfb8d26dabab4b4cb13140188b46153e685ec27a765e50dd92aff939c63b18c
3
+ metadata.gz: ff69015b104dada61abed7c68ad1f17c4f2f0d0ead6e05cf445060f69f4064aa
4
+ data.tar.gz: 00f4b9f8551e568d4887d4072adb3e0ba0e8465e412d9c419f45a19eb1a8725a
5
5
  SHA512:
6
- metadata.gz: cddbc0862debf6fa1895d209d9a4c6bdf0a97d52e5329a44bb7b5163eaece5315e0bf4ec35b02aa60aedccd9397362f13cd55b3d81592599ed597b82f8e4ba2a
7
- data.tar.gz: ef5bc2e82879b1326fe3375385ee0c7aeb5a671686df54305dafbbd42bee581763d1c8ded9998ce81cf91174f2d21899420cf47bc731369586120621e8df1869
6
+ metadata.gz: 75262234b40b10f6de6e4b650c7a7ad024c841d324acb44fadef6042f9725c1f1f1f423bb7d55c7ca300fcf54edf18f033a149331667c907f772ba7d1991e7e9
7
+ data.tar.gz: 50eb75a5f7b293d873f9b2014ec642779e7622da4ae25e6a79352f3ed61e3e93ea13c1b5f53dcdb4e8f34337cbb29b1b7d99753fe19755a3fbb89512091220c4
data/Gemfile CHANGED
@@ -4,5 +4,6 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "sqlite3"
7
- gem "pbbuilder", "~> 0.3.0"
7
+ gem "pbbuilder", "~> 0.10.0"
8
8
  gem "standard"
9
+ gem "pry"
data/README.md CHANGED
@@ -21,6 +21,21 @@ Or install it yourself as:
21
21
  $ gem install rails_twirp
22
22
  ```
23
23
 
24
+ ## Installing correct protobuf version for M1 Mac Chips
25
+
26
+ If you run into an issue with protobuf universal-darwin version, please paste this in your Gemfile as recommended by @bouke :
27
+
28
+ ```ruby
29
+ # HACK(bouk): Overwrite Bundler's platform matcher to ignore universal CPU
30
+ # The protobuf and gRPC 'universal' macOS gems break on M1
31
+ module Bundler::MatchPlatform
32
+ def match_platform(p)
33
+ return false if ::Gem::Platform === platform && platform.cpu == "universal"
34
+ Bundler::MatchPlatform.platforms_match?(platform, p)
35
+ end
36
+ end
37
+ ```
38
+
24
39
  ## Contributing
25
40
  Contribution directions go here.
26
41
 
@@ -37,7 +37,7 @@ module RailsTwirp
37
37
  include Rescue
38
38
  include Instrumentation
39
39
 
40
- attr_internal :request, :env, :response_class
40
+ attr_internal :request, :env, :response_class, :rpc_name
41
41
  def initialize
42
42
  @_request = nil
43
43
  @_env = nil
@@ -49,10 +49,11 @@ module RailsTwirp
49
49
  @_http_request ||= ActionDispatch::Request.new(env[:rack_env])
50
50
  end
51
51
 
52
- def dispatch(action, request, response_class, env = {})
52
+ def dispatch(action, request, response_class, rpc_name, env = {})
53
53
  self.request = request
54
54
  self.env = env
55
55
  self.response_class = response_class
56
+ self.rpc_name = rpc_name
56
57
 
57
58
  http_request.controller_instance = self
58
59
 
@@ -61,8 +62,8 @@ module RailsTwirp
61
62
  response_body
62
63
  end
63
64
 
64
- def self.dispatch(action, request, response_class, env = {})
65
- new.dispatch(action, request, response_class, env)
65
+ def self.dispatch(action, request, response_class, rpc_name, env = {})
66
+ new.dispatch(action, request, response_class, rpc_name, env)
66
67
  end
67
68
 
68
69
  # Used by the template renderer to figure out which template to use
@@ -17,7 +17,9 @@ module RailsTwirp
17
17
  info do
18
18
  code = payload.fetch(:code, :internal)
19
19
 
20
- message = +"Completed #{code} in #{event.duration.round}ms (Allocations: #{event.allocations})"
20
+ message = +"Completed #{code}"
21
+ message << ": #{payload[:msg]}" if payload[:msg]
22
+ message << " in #{event.duration.round}ms (Allocations: #{event.allocations})"
21
23
  message << "\n\n" if defined?(Rails.env) && Rails.env.development?
22
24
 
23
25
  message
@@ -56,8 +56,8 @@ module RailsTwirp
56
56
  handler.define_method(method_name) do |req, env|
57
57
  controller_name = mapping.controller.underscore
58
58
  const_name = controller_name.camelize << "Controller"
59
- controller_class = ::ActiveSupport::Dependencies.constantize(const_name)
60
- controller_class.dispatch(action_name, req, response_class, env)
59
+ controller_class = const_name.constantize
60
+ controller_class.dispatch(action_name, req, response_class, name, env)
61
61
  end
62
62
  end
63
63
 
@@ -100,7 +100,7 @@ module RailsTwirp
100
100
  end
101
101
 
102
102
  def set_controller_from_rack_env(env)
103
- @controller = ActionDispatch::Request.new(env).controller_class
103
+ @controller = ActionDispatch::Request.new(env).controller_instance
104
104
  end
105
105
  end
106
106
  end
@@ -1,3 +1,3 @@
1
1
  module RailsTwirp
2
- VERSION = "0.7.1"
2
+ VERSION = "0.9.1"
3
3
  end
data/rails_twirp.gemspec CHANGED
@@ -14,4 +14,5 @@ Gem::Specification.new do |spec|
14
14
 
15
15
  spec.add_dependency "rails", ">= 6.1.3"
16
16
  spec.add_dependency "twirp", "~> 1.7.2"
17
+ spec.required_ruby_version = ">= 3"
17
18
  end
@@ -0,0 +1,5 @@
1
+ class DummyController < RailsTwirp::Base
2
+ def rpc_name_check
3
+ @rpc_name = rpc_name
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ pb.rpc_name @rpc_name
@@ -1,4 +1,4 @@
1
- require "api_twirp"
1
+ require_relative "../../proto/api_twirp"
2
2
 
3
3
  Rails.application.twirp.routes.draw do
4
4
  service RPC::DummyAPI::DummyService do
@@ -9,6 +9,7 @@ Rails.application.twirp.routes.draw do
9
9
  rpc "RaiseError", to: "pings#raise_error"
10
10
  rpc "UncaughtError", to: "pings#uncaught_raise"
11
11
  rpc "BeforeError", to: "pings#before_error"
12
+ rpc "RpcNameCheck", to: "dummy#rpc_name_check"
12
13
  end
13
14
 
14
15
  scope module: :testmod do
@@ -13,6 +13,7 @@ service Dummy {
13
13
  rpc UncaughtError(PingRequest) returns (PingResponse);
14
14
  rpc BeforeError(PingRequest) returns (PingResponse);
15
15
  rpc Nested(PingRequest) returns (PingResponse);
16
+ rpc RpcNameCheck(RpcNameCheckRequest) returns (RpcNameCheckResponse);
16
17
  }
17
18
 
18
19
  message PingRequest {
@@ -22,3 +23,8 @@ message PingRequest {
22
23
  message PingResponse {
23
24
  string double_name = 2;
24
25
  }
26
+
27
+ message RpcNameCheckRequest{}
28
+ message RpcNameCheckResponse{
29
+ string rpc_name = 1;
30
+ }
@@ -11,6 +11,11 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
11
11
  add_message "dummy.api.PingResponse" do
12
12
  optional :double_name, :string, 2
13
13
  end
14
+ add_message "dummy.api.RpcNameCheckRequest" do
15
+ end
16
+ add_message "dummy.api.RpcNameCheckResponse" do
17
+ optional :rpc_name, :string, 1
18
+ end
14
19
  end
15
20
  end
16
21
 
@@ -18,5 +23,7 @@ module RPC
18
23
  module DummyAPI
19
24
  PingRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("dummy.api.PingRequest").msgclass
20
25
  PingResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("dummy.api.PingResponse").msgclass
26
+ RpcNameCheckRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("dummy.api.RpcNameCheckRequest").msgclass
27
+ RpcNameCheckResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("dummy.api.RpcNameCheckResponse").msgclass
21
28
  end
22
29
  end
@@ -1,4 +1,4 @@
1
- # Code generated by protoc-gen-twirp_ruby 1.6.0, DO NOT EDIT.
1
+ # Code generated by protoc-gen-twirp_ruby 1.8.0, DO NOT EDIT.
2
2
  require 'twirp'
3
3
  require_relative 'api_pb.rb'
4
4
 
@@ -15,6 +15,7 @@ module RPC
15
15
  rpc :UncaughtError, PingRequest, PingResponse, :ruby_method => :uncaught_error
16
16
  rpc :BeforeError, PingRequest, PingResponse, :ruby_method => :before_error
17
17
  rpc :Nested, PingRequest, PingResponse, :ruby_method => :nested
18
+ rpc :RpcNameCheck, RpcNameCheckRequest, RpcNameCheckResponse, :ruby_method => :rpc_name_check
18
19
  end
19
20
 
20
21
  class DummyClient < Twirp::Client
@@ -0,0 +1,10 @@
1
+ require "test_helper"
2
+
3
+ class DummyControllerTest < RailsTwirp::IntegrationTest
4
+ test "controller gets rpc name" do
5
+ req = RPC::DummyAPI::RpcNameCheckRequest.new
6
+ rpc RPC::DummyAPI::DummyService, "RpcNameCheck", req
7
+ assert_instance_of RPC::DummyAPI::RpcNameCheckResponse, response
8
+ assert_equal "RpcNameCheck", response.rpc_name
9
+ end
10
+ end
@@ -61,4 +61,10 @@ class PingControllerTest < RailsTwirp::IntegrationTest
61
61
  assert_equal "yOuR ReQuEsT Is mAlFoRmEd", response.msg
62
62
  assert_equal :malformed, response.code
63
63
  end
64
+
65
+ test "controller is set to the controller that handled the request" do
66
+ req = RPC::DummyAPI::PingRequest.new(name: "Bouke")
67
+ rpc RPC::DummyAPI::DummyService, "Ping", req
68
+ assert_instance_of PingsController, controller
69
+ end
64
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_twirp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-01 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -79,6 +79,7 @@ files:
79
79
  - test/dummy/app/controllers/application_controller.rb
80
80
  - test/dummy/app/controllers/application_twirp_controller.rb
81
81
  - test/dummy/app/controllers/concerns/.keep
82
+ - test/dummy/app/controllers/dummy_controller.rb
82
83
  - test/dummy/app/controllers/pings_controller.rb
83
84
  - test/dummy/app/controllers/testmod/nested/other_controller.rb
84
85
  - test/dummy/app/helpers/application_helper.rb
@@ -88,6 +89,7 @@ files:
88
89
  - test/dummy/app/mailers/application_mailer.rb
89
90
  - test/dummy/app/models/application_record.rb
90
91
  - test/dummy/app/models/concerns/.keep
92
+ - test/dummy/app/views/dummy/rpc_name_check.pb.pbbuilder
91
93
  - test/dummy/app/views/layouts/application.html.erb
92
94
  - test/dummy/app/views/layouts/mailer.html.erb
93
95
  - test/dummy/app/views/layouts/mailer.text.erb
@@ -131,6 +133,7 @@ files:
131
133
  - test/dummy/public/apple-touch-icon-precomposed.png
132
134
  - test/dummy/public/apple-touch-icon.png
133
135
  - test/dummy/public/favicon.ico
136
+ - test/dummy_test.rb
134
137
  - test/other_controller_test.rb
135
138
  - test/ping_controller_test.rb
136
139
  - test/rails_twirp_test.rb
@@ -147,14 +150,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
150
  requirements:
148
151
  - - ">="
149
152
  - !ruby/object:Gem::Version
150
- version: '0'
153
+ version: '3'
151
154
  required_rubygems_version: !ruby/object:Gem::Requirement
152
155
  requirements:
153
156
  - - ">="
154
157
  - !ruby/object:Gem::Version
155
158
  version: '0'
156
159
  requirements: []
157
- rubygems_version: 3.2.22
160
+ rubygems_version: 3.2.26
158
161
  signing_key:
159
162
  specification_version: 4
160
163
  summary: Integrate Twirp into Rails
@@ -168,6 +171,7 @@ test_files:
168
171
  - test/dummy/app/controllers/application_controller.rb
169
172
  - test/dummy/app/controllers/application_twirp_controller.rb
170
173
  - test/dummy/app/controllers/concerns/.keep
174
+ - test/dummy/app/controllers/dummy_controller.rb
171
175
  - test/dummy/app/controllers/pings_controller.rb
172
176
  - test/dummy/app/controllers/testmod/nested/other_controller.rb
173
177
  - test/dummy/app/helpers/application_helper.rb
@@ -177,6 +181,7 @@ test_files:
177
181
  - test/dummy/app/mailers/application_mailer.rb
178
182
  - test/dummy/app/models/application_record.rb
179
183
  - test/dummy/app/models/concerns/.keep
184
+ - test/dummy/app/views/dummy/rpc_name_check.pb.pbbuilder
180
185
  - test/dummy/app/views/layouts/application.html.erb
181
186
  - test/dummy/app/views/layouts/mailer.html.erb
182
187
  - test/dummy/app/views/layouts/mailer.text.erb
@@ -220,6 +225,7 @@ test_files:
220
225
  - test/dummy/public/apple-touch-icon-precomposed.png
221
226
  - test/dummy/public/apple-touch-icon.png
222
227
  - test/dummy/public/favicon.ico
228
+ - test/dummy_test.rb
223
229
  - test/other_controller_test.rb
224
230
  - test/ping_controller_test.rb
225
231
  - test/rails_twirp_test.rb