twirp-on-rails 1.0.1.pre → 1.1.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: 2925a659b9c79db0bfced51d9f8e8c3c86a9c9b4977f64611f7f57d7b2597c00
4
- data.tar.gz: 56abcb2fa1e40241eef7f3199529bf4a83971f82358f679526a38b482c12cb79
3
+ metadata.gz: 5f09ec24234c61ab85dc6ab6e03768c16e4fa7110fe5e5771240ca94633996eb
4
+ data.tar.gz: 569db17177ad607e4de0a9f94cf380857c48e408f5e7937ed951bd549d5a0431
5
5
  SHA512:
6
- metadata.gz: 28a1b6ec586b9e129a64390a5e727aee495a2c624d74ca9b94ac0a1548b5fd36d4951a6e1bc256ca560ea3909a45c4e637dce401a8a77953d2faa6628644674e
7
- data.tar.gz: 661c948ab6ca8b80d83fd882581d4e1246e541aebb2416e62fcafa1f202454453d8ccd7dadcb9ef0b6b8171eefef68aa19794d647595d2fe1a49e7c35fd8a0d4
6
+ metadata.gz: 542712540c037f4be6ac5f322f45f72a44f55705eb813f941769317afcb17ce1853089524cdf725c61bad411fc73a8ae8be7428a8b3846df6ae9604581d5f90e
7
+ data.tar.gz: be401e0761378d95a08bc4d493582450cf5e979e288f578d63c25dd00a69bcc7033b16f77fb31bf0100c2dc1c5a7007fe1c69a8140410b0b4ee5f2238ecfd499
data/.standard.yml CHANGED
@@ -2,3 +2,6 @@ ruby_version: 2.7
2
2
  plugins:
3
3
  - standard-performance
4
4
  - standard-rails
5
+ ignore:
6
+ - '**/*_pb.rb'
7
+ - '**/*_twirp.rb'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.1.0] - 2024-09-12
4
+
5
+ - Respect package namespace when looking for handlers.
6
+
3
7
  ## [0.1.0] - 2022-12-23
4
8
 
5
9
  - Initial release
data/Gemfile CHANGED
@@ -10,6 +10,6 @@ gem "rake"
10
10
  gem "debug"
11
11
  gem "rspec-rails"
12
12
  gem "sqlite3", "~> 1.4"
13
- gem "standard"
13
+ gem "standard", ">= 1.35.1"
14
14
  gem "standard-performance"
15
15
  gem "standard-rails"
data/README.md CHANGED
@@ -86,7 +86,26 @@ end
86
86
 
87
87
  Each handler method should return the appropriate Protobuf, or a `Twirp::Error`.
88
88
 
89
- TODO: Give more examples of both
89
+ #### Packages and Namespacing
90
+
91
+ Handlers can live in directories that reflect the service's package. For example, `haberdasher.proto` defines:
92
+
93
+ ```protobuf
94
+ package twirp.example.haberdasher;
95
+ ```
96
+
97
+ You can use the full path, or because many projects have only one namespace, we also let you skip the namespace for simplicity:
98
+
99
+ We look for the handler in either location:
100
+
101
+ `app/handlers/twirp/example/haberdasher/haberdasher_service_handler.rb` defines `Twirp::Example::Haberdasher::HaberdasherServiceHandler`
102
+
103
+ or
104
+
105
+ `app/handlers/haberdasher_service_handler.rb` defines `HaberdasherServiceHandler`
106
+
107
+
108
+ TODO: Give more examples of handlers
90
109
 
91
110
  ### Familiar Callbacks
92
111
 
@@ -4,7 +4,13 @@ module Twirp
4
4
  module Rails
5
5
  class Dispatcher
6
6
  def initialize(service_class)
7
- @service_handler = "#{service_class.service_name}Handler".constantize
7
+ # Check for a handler in the service's namespace, or in the root namespace
8
+ # e.g. Twirp::Example::Cobbler::CobblerHandler or ::CobblerHandler
9
+ @service_handler = if Object.const_defined?("#{service_class.module_parent}::#{service_class.service_name}Handler")
10
+ "#{service_class.module_parent}::#{service_class.service_name}Handler".constantize
11
+ else
12
+ "#{service_class.service_name}Handler".constantize
13
+ end
8
14
  end
9
15
 
10
16
  def respond_to_missing?(method, *)
@@ -32,7 +32,7 @@ module Twirp
32
32
  when "POST"
33
33
  status, headers, body = response = @app.call(env)
34
34
  # Rack 3 settles on only allowing lowercase headers
35
- if Rack.release < "3.0"
35
+ if ::Rack.release < "3.0"
36
36
  headers = ::Rack::Utils::HeaderHash[headers]
37
37
  end
38
38
 
@@ -40,7 +40,7 @@ module Twirp
40
40
  response[0] = 304
41
41
  headers.delete(::Rack::CONTENT_TYPE)
42
42
  headers.delete(::Rack::CONTENT_LENGTH)
43
- response[2] = Rack::BodyProxy.new([]) do
43
+ response[2] = ::Rack::BodyProxy.new([]) do
44
44
  body.close if body.respond_to?(:close)
45
45
  end
46
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Twirp
4
4
  module Rails
5
- VERSION = "1.0.1.pre"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twirp-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.pre
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Morrison
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-05-20 00:00:00.000000000 Z
12
+ date: 2024-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.5.9
91
+ rubygems_version: 3.5.16
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Use Twirp RPC with Rails