rails_twirp 0.7.0 → 0.9.0

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: 0ed88410115867b689de324aeaf99b91ba473d3aa573915d9bec5de1142b7986
4
- data.tar.gz: dadc45ad3c6ed38f6791e8a45573127c69297772a7b0ae4861a2867dadf26d09
3
+ metadata.gz: e1ac2840887dd15ea43114d7b0d25901c05e3288fa10d6cdcd8d00d4dabc8e74
4
+ data.tar.gz: 59ff25b65ad6bd62f1ebc537bc11017da58b6ce6e1f4a74cae9e1c7f35454508
5
5
  SHA512:
6
- metadata.gz: 976f3755035c22c65db62aa4b82e8019bf816e5e30cec968e19c5345630aa1b7c6d51d38439e267fde4d9696ce05667c5a2ed2566953bbe87a175ac2ea9df93f
7
- data.tar.gz: f3c1460d7cd0ae988e8aabbb516afd1983b975e8aee872f295eb3017061a51500667ee1ecbd226f2260c03f179ad94560227710fc98095e0e60749288271d406
6
+ metadata.gz: fd193ba67f59a313b463a2745418329d33585505164124810abdbd556ce808717064e6dde4c249cd50865951a9e1155f085adc0b556860eb1a83d5714206833a
7
+ data.tar.gz: 2795b73a1cf25688ff7abea8db81af893b23374297dbd9128e6d9b642ee3bce4d4026d83d660aa3158367fd0e357987e2d71717e8b4dabe5e2b86720fbd4b74a
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
 
@@ -7,7 +7,7 @@ module RailsTwirp
7
7
 
8
8
  attr_reader :response, :request, :controller
9
9
  attr_writer :mount_path
10
- alias :mount_path! :mount_path=
10
+ alias_method :mount_path!, :mount_path=
11
11
 
12
12
  def initialize(name)
13
13
  super
@@ -19,7 +19,7 @@ module RailsTwirp
19
19
  @host || DEFAULT_HOST
20
20
  end
21
21
  attr_writer :host
22
- alias :host! :host=
22
+ alias_method :host!, :host=
23
23
 
24
24
  def https?
25
25
  @https
@@ -1,3 +1,3 @@
1
1
  module RailsTwirp
2
- VERSION = "0.7.0"
2
+ VERSION = "0.9.0"
3
3
  end
data/rails_twirp.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.files = `git ls-files`.split("\n")
13
13
  spec.test_files = `git ls-files -- test/*`.split("\n")
14
14
 
15
- spec.add_dependency "rails", "~> 6.1.3"
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
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_twirp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
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-04-22 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 6.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 6.1.3
27
27
  - !ruby/object:Gem::Dependency
@@ -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,7 +150,7 @@ 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
  - - ">="
@@ -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