twirp-rails 0.1.0 → 0.1.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: 9dcf037d0a667d0d0279eb44e44f83b14483921b93c087bccf212e2961d97e82
4
- data.tar.gz: ebd43a7b27ee04d31a5e07daa23af429003a9c6ecce93a241e7c76e54f402a34
3
+ metadata.gz: ee27c7c874d0d00a2af30d47d7e717e1d702bb5efc0d06c0d3046a57d1391c3d
4
+ data.tar.gz: d2644368846f960c4a2b91aca62651dd4f526fea098fc56cbc2ed0a4ff0446f2
5
5
  SHA512:
6
- metadata.gz: eece932d46ad2dd988db38915d7e89e3a559072f82799a03fda573c531d66135e4e534f486235443be1f2cf1d682cc51b5ae9da29d3bc5e051f2f850f0a1f58a
7
- data.tar.gz: ad9efed9706d6ff118a98228c27cab0cdb02cfb05cd98461047e98a2ad01f2930c3ff5c1fb8770f57ca2dc3c4aa42c79ee11267f9707ad0a9217228d1983ec2c
6
+ metadata.gz: e7ae120cbd5ad07199042c4066d5fb3815e7c05d417075ae9807fade9d4dbea598e343a2fdb7428b37eba3bcd1f9d4192b6e644b993d675783e68ab91355b5d7
7
+ data.tar.gz: 010c624299e0cdf5507c1afa4900493a93b42c8cb9e93fd774bb4218e3e77e5e0fb90dad346a47d1f23ddb63c8d490a93ce6b597cbccb755eb03ca959351b5bc
@@ -0,0 +1,10 @@
1
+ # v0.1.1 / 2019-04-27
2
+
3
+ ## Enhancements
4
+
5
+ * Add catch-all handler at the bottom of routes to rescue `bad_route case.
6
+ * Printing all rpc endpoints, instead of printing routes per service.
7
+
8
+ # v0.1.0 / 2019-04-26
9
+
10
+ Initial release
data/README.md CHANGED
@@ -10,7 +10,8 @@ Twirp for Rails
10
10
  $ bin/rails routes
11
11
 
12
12
  Prefix Verb URI Pattern Controller#Action
13
- POST /twirp/HelloService(.:format) hello#hello,hi,greet
13
+ /twirp/HelloService/Greet hello
14
+ /twirp/HelloService/Hi hello
14
15
  ```
15
16
 
16
17
  ## Installation
@@ -33,7 +34,7 @@ Or install it yourself as:
33
34
 
34
35
  After insalled, put the configuration file as follows:
35
36
 
36
- ```
37
+ ```ruby
37
38
  # config/initializers/twirp_rails.rb
38
39
 
39
40
  Twirp::Rails.configuration do |c|
@@ -46,7 +47,7 @@ end
46
47
 
47
48
  Add the line `use_twirp` in `config/routes.rb`. By this, you can tell Rails app what endpoints to be served.
48
49
 
49
- ```
50
+ ```ruby
50
51
  # config/routes.rb
51
52
 
52
53
  Rails.application.routes.draw do
@@ -58,13 +59,13 @@ end
58
59
 
59
60
  Next, let's link handlers(a.k.a controllers) with services. `bind` method can bind them.
60
61
 
61
- ```
62
+ ```ruby
62
63
  class HelloHandler
63
64
  include Twirp::Rails::Helpers
64
65
 
65
66
  bind HelloService
66
67
 
67
- def hello(_req, _env)
68
+ def greet(_req, _env)
68
69
  HelloResponse.new(message: 'hello')
69
70
  end
70
71
  end
@@ -76,7 +77,8 @@ So now corresponding routes will be defined.
76
77
  $ bin/rails routes
77
78
 
78
79
  Prefix Verb URI Pattern Controller#Action
79
- POST /twirp/HelloService(.:format) hello#hello,hi,greet
80
+ /twirp/HelloService/Greet hello
81
+ /twirp/HelloService/Hi hello
80
82
  ```
81
83
 
82
84
  ## Development
@@ -15,12 +15,13 @@ module Twirp
15
15
  REMOVABLE_SUFFIX_RE = /(_handler|_controller)\z/
16
16
 
17
17
  def inspect
18
- handler = instance_variable_get(:@handler).class.name.underscore.sub(REMOVABLE_SUFFIX_RE, '')
19
- methods = self.class.rpcs.values.map { |h| h[:ruby_method].to_s }.sort.join(',')
20
- [handler, methods].join('#')
18
+ instance_variable_get(:@handler).class.name.underscore.sub(REMOVABLE_SUFFIX_RE, '')
21
19
  end
22
20
  end
23
21
 
22
+ # A null hanlder to cause a bad_route error by unexpected rpc call, instead of raising a routing error by Rails.
23
+ class CatchAllHandler; end
24
+
24
25
  def self.install!
25
26
  ActionDispatch::Routing::Mapper.send :include, Twirp::Rails::Routes::Helper
26
27
  end
@@ -36,8 +37,17 @@ module Twirp
36
37
  routes.scope options[:scope] || 'twirp' do
37
38
  @services.each do |service|
38
39
  service.extend Inspectable
39
- @routes.mount service, at: service.full_name
40
+ service.class.rpcs.values.each do |h|
41
+ rpc_method = h[:rpc_method]
42
+ path = service.full_name + '/' + rpc_method.to_s
43
+ @routes.match path, to: service, format: false, via: :all
44
+ end
40
45
  end
46
+
47
+ # Set catch-all route
48
+ null_service = ::Twirp::Service.new(CatchAllHandler.new)
49
+ null_service.extend Inspectable
50
+ routes.mount null_service, at: '/'
41
51
  end
42
52
  end
43
53
  end
@@ -1,5 +1,5 @@
1
1
  module Twirp
2
2
  module Rails
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twirp-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobuhiro Nikushi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-26 00:00:00.000000000 Z
11
+ date: 2019-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -90,6 +90,7 @@ files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
92
  - ".travis.yml"
93
+ - CHANGELOG.md
93
94
  - Gemfile
94
95
  - LICENSE.txt
95
96
  - README.md