twirp_rails 0.4.6 → 0.4.11

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: 81fc1779265896c8e94b3e133dcb859f9cb88b8c50b243887ba40894ccfb5840
4
- data.tar.gz: 481e078b49b5ffce44787f011e8702919efc0c6c1e657c14dd13e13d08065b78
3
+ metadata.gz: 5da53563962b8a7e80b095b7e26b1e1836d5b55456ec967d8df459f9b557d571
4
+ data.tar.gz: 26ff87c7460f1a4d53487b414c4c7174e0b05df9178c34642eca8d60c6bd9ed5
5
5
  SHA512:
6
- metadata.gz: 13fd0e6576cb5189487ffe8cfd48c7443faaf4ab94bfdb9c7500d2d7104ddf3cab9a4a0f74acce5e80616c6e998c3b757c75ece1fb0e62d59b3c6fc5ff71afa4
7
- data.tar.gz: 281573e3920d9c57f7089ac0b2d5fdf418c70a30de16845ea6ec719b1d7753fac00862022523262abff254e086f60be4f09d97aa1bce38d36a09bf0c266a7d53
6
+ metadata.gz: 4271e7ae75cc007dcc4bc2fd38748a0084e3fde41c834dbc859ef1152138f02d3c6eca09c957bf3dbb9720f47c96dcdc297f57d48f417238abd357859998ec59
7
+ data.tar.gz: c84132c42322964c4150191bf1d3201d9d3128fca47a8b70af4285b59e1d70ab28271e96234d675645c5b0274941307bd4f9da4840d2234b4c32f565456206d1
data/.gitignore CHANGED
@@ -9,6 +9,7 @@
9
9
  /.idea/
10
10
 
11
11
  .rspec_status
12
+ .rakeTasks
12
13
 
13
14
  /spec/dummy/tmp
14
15
  /spec/dummy/log
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twirp_rails (0.4.5)
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.3.1)
12
- actionview (= 6.0.3.1)
13
- activesupport (= 6.0.3.1)
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.3.1)
19
- activesupport (= 6.0.3.1)
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.3.1)
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)
@@ -33,15 +33,15 @@ GEM
33
33
  crass (1.0.6)
34
34
  diff-lcs (1.3)
35
35
  erubi (1.9.0)
36
- faraday (0.17.3)
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.0)
42
- i18n (1.8.2)
41
+ google-protobuf (3.12.2)
42
+ i18n (1.8.3)
43
43
  concurrent-ruby (~> 1.0)
44
- loofah (2.5.0)
44
+ loofah (2.6.0)
45
45
  crass (~> 1.0.2)
46
46
  nokogiri (>= 1.5.9)
47
47
  method_source (0.9.2)
@@ -53,7 +53,7 @@ GEM
53
53
  pry (0.12.2)
54
54
  coderay (~> 1.1.0)
55
55
  method_source (~> 0.9.0)
56
- rack (2.2.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.3.1)
65
- actionpack (= 6.0.3.1)
66
- activesupport (= 6.0.3.1)
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)
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 ErrorTranslator < TwirpRails::ErrorHandling::Base
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/twirp_ruby.rb
180
+ # config/initializers/twirp_rails.rb
181
181
  # ...
182
- config.twirp_exception_translator_class = 'ErrorTranslator'
182
+ config.twirp_exception_translator_class = 'ApplicationErrorTranslator'
183
183
  # ...
184
184
  ```
185
185
 
@@ -12,6 +12,14 @@ module TwirpRails
12
12
  def method_missing(method, *args)
13
13
  handler.public_send method, *args
14
14
  rescue => e
15
+ if ENV['RAISE_TWIRP_ERRORS'].present?
16
+ raise e
17
+ else
18
+ Rails.logger.warn("Muted error: #{e.message}")
19
+ Rails.logger.warn("Muted error: #{e.full_message}")
20
+ Rails.logger.warn('Enable raise with RAISE_TWIRP_ERRORS env variable')
21
+ end
22
+
15
23
  translator_class.exception_to_twirp(e, handler)
16
24
  end
17
25
  # rubocop:enable Style/MethodMissingSuper
@@ -31,7 +39,7 @@ module TwirpRails
31
39
 
32
40
  def raise_on_error(twirp_result)
33
41
  if twirp_result.error
34
- exception = translator_class.twirp_to_exception(twirp_result.error)
42
+ exception = translator_class.twirp_to_exception(twirp_result.error, client)
35
43
  raise exception
36
44
  else
37
45
  twirp_result
@@ -43,15 +51,15 @@ module TwirpRails
43
51
  if method =~ /!$/
44
52
  # when we call a bang version of client method - raise exception translated from error
45
53
  method = method[0..-2]
46
- raise_on_error client.public_send(method, args)
54
+ raise_on_error client.public_send(method, *args)
47
55
  else
48
- client.public_send method, args
56
+ client.public_send method, *args
49
57
  end
50
58
  end
51
59
  # rubocop:enable Style/MethodMissingSuper
52
60
 
53
61
  def respond_to_missing?(method, include_all = false)
54
- handler.respond_to?(method, include_all)
62
+ client.respond_to?(method, include_all)
55
63
  end
56
64
  end
57
65
 
@@ -31,7 +31,7 @@ module Twirp
31
31
  proto_files = Dir.glob protos_mask
32
32
 
33
33
  proto_files.each do |file|
34
- cmd = protoc.cmd(file)
34
+ cmd = protoc.cmd(file, false)
35
35
 
36
36
  `#{cmd}`
37
37
 
@@ -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 = 'SampleTranslator'
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: nil)
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: false)
32
- flags = "--proto_path=#{src_path} " \
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 :skip_swagger, type: :boolean, default: false
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 swagger_out_path if gen_swagger
70
+ FileUtils.mkdir_p cfg.swagger_output_path if gen_swagger
71
71
 
72
- cmd = protoc.cmd(file, gen_swagger: 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
- !options[:skip_swagger] && cfg.swagger_output_path
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, swagger_out_path: swagger_out_path)
199
+ @protoc ||= ProtocAdapter.new(src_path, dst_path, cfg.swagger_output_path)
204
200
  end
205
201
  end
@@ -1,3 +1,3 @@
1
1
  module TwirpRails
2
- VERSION = '0.4.6'.freeze
2
+ VERSION = '0.4.11'.freeze
3
3
  end
@@ -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.6
4
+ version: 0.4.11
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-06-03 00:00:00.000000000 Z
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.3
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: []