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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +8 -6
- data/lib/twirp/rails/routes.rb +14 -4
- data/lib/twirp/rails/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee27c7c874d0d00a2af30d47d7e717e1d702bb5efc0d06c0d3046a57d1391c3d
|
4
|
+
data.tar.gz: d2644368846f960c4a2b91aca62651dd4f526fea098fc56cbc2ed0a4ff0446f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7ae120cbd5ad07199042c4066d5fb3815e7c05d417075ae9807fade9d4dbea598e343a2fdb7428b37eba3bcd1f9d4192b6e644b993d675783e68ab91355b5d7
|
7
|
+
data.tar.gz: 010c624299e0cdf5507c1afa4900493a93b42c8cb9e93fd774bb4218e3e77e5e0fb90dad346a47d1f23ddb63c8d490a93ce6b597cbccb755eb03ca959351b5bc
|
data/CHANGELOG.md
ADDED
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
|
-
|
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
|
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
|
-
|
80
|
+
/twirp/HelloService/Greet hello
|
81
|
+
/twirp/HelloService/Hi hello
|
80
82
|
```
|
81
83
|
|
82
84
|
## Development
|
data/lib/twirp/rails/routes.rb
CHANGED
@@ -15,12 +15,13 @@ module Twirp
|
|
15
15
|
REMOVABLE_SUFFIX_RE = /(_handler|_controller)\z/
|
16
16
|
|
17
17
|
def inspect
|
18
|
-
|
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
|
-
|
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
|
data/lib/twirp/rails/version.rb
CHANGED
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.
|
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-
|
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
|