twirp_rails 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/lib/twirp_rails/generators/twirp/twirp_generator.rb +18 -9
- data/lib/twirp_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f76a67c6644535dc835e68bb6b47b28661dca6922b9733653f0480e297f65bb1
|
4
|
+
data.tar.gz: f0a855d0cb9d1a0b693e5b11c03d7bdca9486ff12bf82ac103298bfdf67dfe88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22b8a3a2c75e2a5084a5184c1137726ce3f8978f111a2cd1749028492276b518ab2c03b19e799d9ec858023fe51ce01d79f6d7702357e761ec555e90ac832a5b
|
7
|
+
data.tar.gz: 87bf3f8cc09b9694cdc1f949de56d38f1a6283bc2d6237b0e06f75b15266c4009015a13efa6f74966623d01db2773cc3e4a51fb7bce17401b14830f78c795d4d
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## 0.1.3 - 2020-01-28
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- convert package.message type to Package::Message
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- twirp_ruby missing module workaround https://github.com/twitchtv/twirp-ruby/issues/48
|
14
|
+
|
7
15
|
## 0.1.2 - 2020-01-27
|
8
16
|
|
9
17
|
### Fixed
|
data/Gemfile.lock
CHANGED
@@ -27,17 +27,23 @@ class TwirpGenerator < Rails::Generators::NamedBase
|
|
27
27
|
|
28
28
|
def generate_twirp_files
|
29
29
|
in_root do
|
30
|
-
|
30
|
+
proto_files = Dir.glob 'app/protos/**/*.proto'
|
31
31
|
|
32
|
-
|
32
|
+
proto_files.each do |file|
|
33
|
+
cmd = protoc_cmd(file)
|
33
34
|
|
34
|
-
|
35
|
+
`#{cmd}`
|
36
|
+
|
37
|
+
raise "protoc failure: #{cmd}" unless $?.success?
|
38
|
+
end
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
42
|
PROTO_RPC_REGEXP = /\brpc\s+(\S+)\s*\(\s*(\S+)\s*\)\s*returns\s*\(\s*(\S+)\s*\)/m.freeze
|
43
|
+
|
39
44
|
def generate_handler
|
40
|
-
|
45
|
+
methods = proto_content.scan(PROTO_RPC_REGEXP).map do |method, arg_type, result_type|
|
46
|
+
result_type = proto_type_to_ruby(result_type)
|
41
47
|
<<-RUBY
|
42
48
|
def #{method.underscore}(req, _env)
|
43
49
|
#{result_type}.new
|
@@ -45,11 +51,11 @@ class TwirpGenerator < Rails::Generators::NamedBase
|
|
45
51
|
RUBY
|
46
52
|
end.join("\n")
|
47
53
|
|
48
|
-
#
|
54
|
+
# Let us assume that the service name is the same file name
|
49
55
|
create_file "app/rpc/#{file_name}_handler.rb", <<~RUBY
|
50
56
|
class #{class_name}Handler
|
51
57
|
|
52
|
-
#{
|
58
|
+
#{methods}end
|
53
59
|
RUBY
|
54
60
|
end
|
55
61
|
|
@@ -63,6 +69,10 @@ class TwirpGenerator < Rails::Generators::NamedBase
|
|
63
69
|
|
64
70
|
private
|
65
71
|
|
72
|
+
def proto_type_to_ruby(result_type)
|
73
|
+
result_type.split('.').map(&:camelize).join('::')
|
74
|
+
end
|
75
|
+
|
66
76
|
def from_rails_root(&block)
|
67
77
|
old_dir = Dir.pwd
|
68
78
|
Dir.chdir Rails.root
|
@@ -71,12 +81,11 @@ class TwirpGenerator < Rails::Generators::NamedBase
|
|
71
81
|
Dir.chdir old_dir
|
72
82
|
end
|
73
83
|
|
74
|
-
def protoc_cmd
|
84
|
+
def protoc_cmd(files)
|
75
85
|
FileUtils.mkdir_p 'lib/twirp'
|
76
86
|
flags = "--proto_path=app/protos --ruby_out=lib/twirp --twirp_ruby_out=lib/twirp --plugin=#{PLUGIN_PATH}"
|
77
87
|
|
78
|
-
|
79
|
-
"#{PROTOC_PATH} #{flags} #{proto_files.join(' ')}"
|
88
|
+
"#{PROTOC_PATH} #{flags} #{files}"
|
80
89
|
end
|
81
90
|
|
82
91
|
def proto_content
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Zimin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twirp
|