twirp_rails 0.4.4 → 0.4.9

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: 974aa187c0fa4e596194362b3aafc3b34e12baacd05b502a1a09bb808cf3ab0c
4
- data.tar.gz: 9f121868824a0cda89c27a8e77d163640ae3b2b23f714c7122353abe2d39bd65
3
+ metadata.gz: 0f1bb0eea590cb282d0b8c08ae969af2e85d09f77da0d6db73768a2e9151aeb6
4
+ data.tar.gz: e4680efb98f114aa18ee751c9f2b894c0baff3b288f2f41487a6fe3175bc54f4
5
5
  SHA512:
6
- metadata.gz: 8898c1ae5bae4e1f024a69a5a29ac71a1130d8198fc376f18a6647f49228b2bbfb9d9b998f16e967a5036c8543e6e373374822e440685b0d6bb14033ecc359b1
7
- data.tar.gz: 6515db4669525602ad53d090af51239ede7a7e2980981704751d210d6c8541e0405c1e8428dc0a13d9267e0140de95db4f93989c09b002185cb060e622627ac7
6
+ metadata.gz: 39d5f15f647f7468adf94ca9c7e90f9791df1f417473920915ed7b0b1e923c4e8d1c17fdb8b61c3a9f9c926e8c8581e4e2c8ec606d5d3341ed8cb0400cd312c0
7
+ data.tar.gz: f5a8f247a6501f1ff4b03834b732a2a9d8ac6c838fe18c941d3834d82ae08f49bf0ecd30f4f7383f1829915be99b9c99ea314ee0f71e2a070afcd178ccf920a6
@@ -1,59 +1,59 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twirp_rails (0.4.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.1)
12
- actionview (= 6.0.2.1)
13
- activesupport (= 6.0.2.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.2.1)
19
- activesupport (= 6.0.2.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.2.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)
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.5)
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.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.11.4-universal-darwin)
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.4.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)
48
48
  mini_portile2 (2.4.0)
49
- minitest (5.14.0)
49
+ minitest (5.14.1)
50
50
  multipart-post (2.1.1)
51
- nokogiri (1.10.8)
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.1.1)
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.1)
65
- actionpack (= 6.0.2.1)
66
- activesupport (= 6.0.2.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)
@@ -91,12 +91,12 @@ GEM
91
91
  rspec-support (3.9.2)
92
92
  thor (1.0.1)
93
93
  thread_safe (0.3.6)
94
- twirp (1.4.1)
95
- faraday (~> 0)
94
+ twirp (1.5.0)
95
+ faraday (< 2)
96
96
  google-protobuf (~> 3.0, >= 3.0.0)
97
- tzinfo (1.2.6)
97
+ tzinfo (1.2.7)
98
98
  thread_safe (~> 0.1)
99
- zeitwerk (2.2.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 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
 
@@ -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
 
@@ -16,8 +16,8 @@ module TwirpRails
16
16
  end
17
17
  # rubocop:enable Style/MethodMissingSuper
18
18
 
19
- def respond_to_missing?(method)
20
- handler.respond_to?(method)
19
+ def respond_to_missing?(method, include_all = false)
20
+ handler.respond_to?(method, include_all)
21
21
  end
22
22
  end
23
23
 
@@ -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
- def respond_to_missing?(method)
54
- handler.respond_to?(method)
53
+ def respond_to_missing?(method, include_all = false)
54
+ client.respond_to?(method, include_all)
55
55
  end
56
56
  end
57
57
 
@@ -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.4'.freeze
2
+ VERSION = '0.4.9'.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.4
4
+ version: 0.4.9
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-07 00:00:00.000000000 Z
11
+ date: 2020-07-23 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.0.6
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: []