twirp_rails 0.4.6 → 0.4.7

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: f6df8a4134b84a9843ad8a0db616c68dee24c88e95346ef48a34db3907f5d975
4
+ data.tar.gz: b113bc311403756b83e6e1464a02504dbd37a6f849a3f3789e22e594191643b0
5
5
  SHA512:
6
- metadata.gz: 13fd0e6576cb5189487ffe8cfd48c7443faaf4ab94bfdb9c7500d2d7104ddf3cab9a4a0f74acce5e80616c6e998c3b757c75ece1fb0e62d59b3c6fc5ff71afa4
7
- data.tar.gz: 281573e3920d9c57f7089ac0b2d5fdf418c70a30de16845ea6ec719b1d7753fac00862022523262abff254e086f60be4f09d97aa1bce38d36a09bf0c266a7d53
6
+ metadata.gz: 8b63a508a6319c3a1d4977c807bc95b9d262e42fca622fe04f1f350c12aa3716eb53873ce8389cc6515d1aa8a60f0c353713af12846d83d4da2a74c80098df1e
7
+ data.tar.gz: b5b8cbf244043de39bf8ae47fcc1569c877e199f9489e87db867a4ee467f099328aad9759e3d11ec34fbd8cb86761d566cdca77606f0c81e09e7ea62b64d3e6e
@@ -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)
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.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandr Zimin