twirp_rails 0.4.5 → 0.4.10
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/Gemfile.lock +22 -22
- data/README.md +3 -3
- data/lib/twirp_rails.rb +11 -0
- data/lib/twirp_rails/error_handling/error_handling_factory.rb +4 -4
- data/lib/twirp_rails/generators/twirp/clients/clients_generator.rb +1 -1
- data/lib/twirp_rails/generators/twirp/init/templates/twirp_rails.rb +1 -1
- data/lib/twirp_rails/generators/twirp/protoc_adapter.rb +19 -12
- data/lib/twirp_rails/generators/twirp/twirp_generator.rb +5 -9
- data/lib/twirp_rails/version.rb +1 -1
- data/twirp_rails.gemspec +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0781426359346a251fd1e21694aea0a5997d7dd777cb500adb7fe1e78c95fc91'
|
4
|
+
data.tar.gz: e8b3b1e10de47f2eb10686eaf9f554258a335834fab7c79b7d946ab27647257f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c60929fae2b45db84e61255efcb5d95347a01fbdefe79b65b4f6eea754f06f8af6ba668db1dc22155f6782ab8384262f6b8ed831fa237f347128dae8abdc17d
|
7
|
+
data.tar.gz: 5ad5e99a83dd34186ee6348337a8e9a0877fb11a7527ce33d07980edd2ac49afdab871ccc23a1865966b6972bb2b452a246e33c003ca709474edc8e62556f73d
|
data/Gemfile.lock
CHANGED
@@ -1,59 +1,59 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
twirp_rails (0.4.
|
4
|
+
twirp_rails (0.4.9)
|
5
5
|
railties (~> 6.0)
|
6
|
-
twirp (~> 1)
|
6
|
+
twirp (~> 1.4)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (6.0.2
|
12
|
-
actionview (= 6.0.2
|
13
|
-
activesupport (= 6.0.2
|
11
|
+
actionpack (6.0.3.2)
|
12
|
+
actionview (= 6.0.3.2)
|
13
|
+
activesupport (= 6.0.3.2)
|
14
14
|
rack (~> 2.0, >= 2.0.8)
|
15
15
|
rack-test (>= 0.6.3)
|
16
16
|
rails-dom-testing (~> 2.0)
|
17
17
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
-
actionview (6.0.2
|
19
|
-
activesupport (= 6.0.2
|
18
|
+
actionview (6.0.3.2)
|
19
|
+
activesupport (= 6.0.3.2)
|
20
20
|
builder (~> 3.1)
|
21
21
|
erubi (~> 1.4)
|
22
22
|
rails-dom-testing (~> 2.0)
|
23
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
-
activesupport (6.0.2
|
24
|
+
activesupport (6.0.3.2)
|
25
25
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
26
|
i18n (>= 0.7, < 2)
|
27
27
|
minitest (~> 5.1)
|
28
28
|
tzinfo (~> 1.1)
|
29
|
-
zeitwerk (~> 2.2)
|
29
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
30
30
|
builder (3.2.4)
|
31
31
|
coderay (1.1.2)
|
32
|
-
concurrent-ruby (1.1.
|
32
|
+
concurrent-ruby (1.1.6)
|
33
33
|
crass (1.0.6)
|
34
34
|
diff-lcs (1.3)
|
35
35
|
erubi (1.9.0)
|
36
|
-
faraday (0.
|
36
|
+
faraday (1.0.1)
|
37
37
|
multipart-post (>= 1.2, < 3)
|
38
38
|
generator_spec (0.9.4)
|
39
39
|
activesupport (>= 3.0.0)
|
40
40
|
railties (>= 3.0.0)
|
41
|
-
google-protobuf (3.12.
|
42
|
-
i18n (1.8.
|
41
|
+
google-protobuf (3.12.2)
|
42
|
+
i18n (1.8.3)
|
43
43
|
concurrent-ruby (~> 1.0)
|
44
|
-
loofah (2.
|
44
|
+
loofah (2.6.0)
|
45
45
|
crass (~> 1.0.2)
|
46
46
|
nokogiri (>= 1.5.9)
|
47
47
|
method_source (0.9.2)
|
48
48
|
mini_portile2 (2.4.0)
|
49
|
-
minitest (5.14.
|
49
|
+
minitest (5.14.1)
|
50
50
|
multipart-post (2.1.1)
|
51
|
-
nokogiri (1.10.
|
51
|
+
nokogiri (1.10.9)
|
52
52
|
mini_portile2 (~> 2.4.0)
|
53
53
|
pry (0.12.2)
|
54
54
|
coderay (~> 1.1.0)
|
55
55
|
method_source (~> 0.9.0)
|
56
|
-
rack (2.
|
56
|
+
rack (2.2.3)
|
57
57
|
rack-test (1.1.0)
|
58
58
|
rack (>= 1.0, < 3)
|
59
59
|
rails-dom-testing (2.0.3)
|
@@ -61,9 +61,9 @@ GEM
|
|
61
61
|
nokogiri (>= 1.6)
|
62
62
|
rails-html-sanitizer (1.3.0)
|
63
63
|
loofah (~> 2.3)
|
64
|
-
railties (6.0.2
|
65
|
-
actionpack (= 6.0.2
|
66
|
-
activesupport (= 6.0.2
|
64
|
+
railties (6.0.3.2)
|
65
|
+
actionpack (= 6.0.3.2)
|
66
|
+
activesupport (= 6.0.3.2)
|
67
67
|
method_source
|
68
68
|
rake (>= 0.8.7)
|
69
69
|
thor (>= 0.20.3, < 2.0)
|
@@ -94,9 +94,9 @@ GEM
|
|
94
94
|
twirp (1.5.0)
|
95
95
|
faraday (< 2)
|
96
96
|
google-protobuf (~> 3.0, >= 3.0.0)
|
97
|
-
tzinfo (1.2.
|
97
|
+
tzinfo (1.2.7)
|
98
98
|
thread_safe (~> 0.1)
|
99
|
-
zeitwerk (2.
|
99
|
+
zeitwerk (2.3.0)
|
100
100
|
|
101
101
|
PLATFORMS
|
102
102
|
ruby
|
data/README.md
CHANGED
@@ -160,7 +160,7 @@ This feature allow to use ruby style exception handling flow in ruby code.
|
|
160
160
|
|
161
161
|
Create class to describe translate error rules
|
162
162
|
```ruby
|
163
|
-
class
|
163
|
+
class ApplicationErrorTranslator < TwirpRails::ErrorHandling::Base
|
164
164
|
# rules to translate exception raised by handler to twirp
|
165
165
|
translate_exception ArgumentError, with: :invalid_argument
|
166
166
|
translate_exception ActiveRecord::NotFound do |exception, handler|
|
@@ -177,9 +177,9 @@ Create class to describe translate error rules
|
|
177
177
|
|
178
178
|
And configure TwirpRails to use it:
|
179
179
|
```ruby
|
180
|
-
# config/initializers/
|
180
|
+
# config/initializers/twirp_rails.rb
|
181
181
|
# ...
|
182
|
-
config.twirp_exception_translator_class = '
|
182
|
+
config.twirp_exception_translator_class = 'ApplicationErrorTranslator'
|
183
183
|
# ...
|
184
184
|
```
|
185
185
|
|
data/lib/twirp_rails.rb
CHANGED
@@ -123,6 +123,17 @@ module TwirpRails
|
|
123
123
|
Time.zone.at seconds
|
124
124
|
end
|
125
125
|
|
126
|
+
# Utility for converting a Ruby Time instance to a
|
127
|
+
# Google::Protobuf::Timestamp.
|
128
|
+
#
|
129
|
+
# @param time [Time] The Time to be converted.
|
130
|
+
#
|
131
|
+
# @return [Google::Protobuf::Timestamp] The converted
|
132
|
+
# Google::Protobuf::Timestamp.
|
133
|
+
def self.time_to_timestamp(time)
|
134
|
+
Google::Protobuf::Timestamp.new(seconds: time.to_i, nanos: time.nsec)
|
135
|
+
end
|
136
|
+
|
126
137
|
def self.client(klass, url)
|
127
138
|
client = klass.new(url)
|
128
139
|
|
@@ -31,7 +31,7 @@ module TwirpRails
|
|
31
31
|
|
32
32
|
def raise_on_error(twirp_result)
|
33
33
|
if twirp_result.error
|
34
|
-
exception = translator_class.twirp_to_exception(twirp_result.error)
|
34
|
+
exception = translator_class.twirp_to_exception(twirp_result.error, client)
|
35
35
|
raise exception
|
36
36
|
else
|
37
37
|
twirp_result
|
@@ -43,15 +43,15 @@ module TwirpRails
|
|
43
43
|
if method =~ /!$/
|
44
44
|
# when we call a bang version of client method - raise exception translated from error
|
45
45
|
method = method[0..-2]
|
46
|
-
raise_on_error client.public_send(method, args)
|
46
|
+
raise_on_error client.public_send(method, *args)
|
47
47
|
else
|
48
|
-
client.public_send method, args
|
48
|
+
client.public_send method, *args
|
49
49
|
end
|
50
50
|
end
|
51
51
|
# rubocop:enable Style/MethodMissingSuper
|
52
52
|
|
53
53
|
def respond_to_missing?(method, include_all = false)
|
54
|
-
|
54
|
+
client.respond_to?(method, include_all)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -36,7 +36,7 @@ TwirpRails.configure do |config|
|
|
36
36
|
# translate_exception Mongoid::Errors::DocumentNotFound, with: :not_found
|
37
37
|
# translate_error :not_found, with: Mongoid::Errors::DocumentNotFound
|
38
38
|
# end
|
39
|
-
# config.twirp_exception_translator_class = '
|
39
|
+
# config.twirp_exception_translator_class = 'ApplicationErrorTranslator'
|
40
40
|
# default:
|
41
41
|
# config.twirp_exception_translator_class = nil
|
42
42
|
end
|
@@ -3,7 +3,7 @@ class ProtocAdapter
|
|
3
3
|
|
4
4
|
attr_reader :twirp_plugin_path, :swagger_plugin_path, :protoc_path
|
5
5
|
|
6
|
-
def initialize(src_path, dst_path, swagger_out_path
|
6
|
+
def initialize(src_path, dst_path, swagger_out_path = nil)
|
7
7
|
@src_path = src_path
|
8
8
|
@dst_path = dst_path
|
9
9
|
@swagger_out_path = swagger_out_path
|
@@ -28,17 +28,8 @@ class ProtocAdapter
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def cmd(files, gen_swagger
|
32
|
-
flags
|
33
|
-
"--ruby_out=#{dst_path} --twirp_ruby_out=#{dst_path} " \
|
34
|
-
"--plugin=#{twirp_plugin_path}"
|
35
|
-
|
36
|
-
if gen_swagger
|
37
|
-
flags += " --plugin=#{swagger_plugin_path}" \
|
38
|
-
" --twirp_swagger_out=#{swagger_out_path}"
|
39
|
-
end
|
40
|
-
|
41
|
-
"#{protoc_path} #{flags} #{files}"
|
31
|
+
def cmd(files, gen_swagger)
|
32
|
+
"#{protoc_path} #{flags(gen_swagger)} #{files}"
|
42
33
|
end
|
43
34
|
|
44
35
|
def check_requirements(check_swagger: false)
|
@@ -62,4 +53,20 @@ class ProtocAdapter
|
|
62
53
|
TEXT
|
63
54
|
end
|
64
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def flags(gen_swagger)
|
60
|
+
[].tap do |flags|
|
61
|
+
flags << "--proto_path=#{src_path}"
|
62
|
+
flags << "--ruby_out=#{dst_path}"
|
63
|
+
flags << "--twirp_ruby_out=#{dst_path}"
|
64
|
+
flags << "--plugin=#{twirp_plugin_path}"
|
65
|
+
|
66
|
+
if gen_swagger
|
67
|
+
flags << "--plugin=#{swagger_plugin_path}"
|
68
|
+
flags << "--twirp_swagger_out=#{swagger_out_path}"
|
69
|
+
end
|
70
|
+
end.join(' ')
|
71
|
+
end
|
65
72
|
end
|
@@ -3,7 +3,7 @@ require 'rails/generators'
|
|
3
3
|
class TwirpGenerator < Rails::Generators::NamedBase
|
4
4
|
source_root File.expand_path('templates', __dir__)
|
5
5
|
|
6
|
-
class_option :
|
6
|
+
class_option :gen_swagger, type: :boolean, default: false
|
7
7
|
class_option :swagger_out, type: :string, default: nil
|
8
8
|
|
9
9
|
def smart_detect_proto_file_name
|
@@ -67,9 +67,9 @@ class TwirpGenerator < Rails::Generators::NamedBase
|
|
67
67
|
proto_files.each do |file|
|
68
68
|
gen_swagger = gen_swagger? && file =~ %r{/#{file_name}\.proto$}
|
69
69
|
|
70
|
-
FileUtils.mkdir_p
|
70
|
+
FileUtils.mkdir_p cfg.swagger_output_path if gen_swagger
|
71
71
|
|
72
|
-
cmd = protoc.cmd(file, gen_swagger
|
72
|
+
cmd = protoc.cmd(file, gen_swagger)
|
73
73
|
|
74
74
|
protoc_files_count += 1
|
75
75
|
swagger_files_count += gen_swagger ? 1 : 0
|
@@ -188,11 +188,7 @@ class TwirpGenerator < Rails::Generators::NamedBase
|
|
188
188
|
end
|
189
189
|
|
190
190
|
def gen_swagger?
|
191
|
-
|
192
|
-
end
|
193
|
-
|
194
|
-
def swagger_out_path
|
195
|
-
options[:swagger_out] || cfg.swagger_output_path
|
191
|
+
options[:gen_swagger] && cfg.swagger_output_path.present?
|
196
192
|
end
|
197
193
|
|
198
194
|
def abort(msg)
|
@@ -200,6 +196,6 @@ class TwirpGenerator < Rails::Generators::NamedBase
|
|
200
196
|
end
|
201
197
|
|
202
198
|
def protoc
|
203
|
-
@protoc ||= ProtocAdapter.new(src_path, dst_path,
|
199
|
+
@protoc ||= ProtocAdapter.new(src_path, dst_path, cfg.swagger_output_path)
|
204
200
|
end
|
205
201
|
end
|
data/lib/twirp_rails/version.rb
CHANGED
data/twirp_rails.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_dependency 'twirp', '~> 1'
|
25
|
+
spec.add_dependency 'twirp', '~> 1.4'
|
26
26
|
spec.add_dependency 'railties', '~> 6.0'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
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.4.
|
4
|
+
version: 0.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Zimin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05
|
11
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twirp
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1'
|
19
|
+
version: '1.4'
|
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
|
-
version: '1'
|
26
|
+
version: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.12'
|
125
|
-
description:
|
125
|
+
description:
|
126
126
|
email:
|
127
127
|
- a.zimin@talenttech.ru
|
128
128
|
executables: []
|
@@ -167,7 +167,7 @@ homepage: https://github.com/severgroup-tt/twirp_rails
|
|
167
167
|
licenses:
|
168
168
|
- MIT
|
169
169
|
metadata: {}
|
170
|
-
post_install_message:
|
170
|
+
post_install_message:
|
171
171
|
rdoc_options: []
|
172
172
|
require_paths:
|
173
173
|
- lib
|
@@ -182,8 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
- !ruby/object:Gem::Version
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
|
-
rubygems_version: 3.1.
|
186
|
-
signing_key:
|
185
|
+
rubygems_version: 3.1.4
|
186
|
+
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: Use twirp-ruby from rails.
|
189
189
|
test_files: []
|