rbs_protobuf 0.1.0 → 0.2.0

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: 6d8369a09563679a8a6c334efe056f6ef462bc1fc9bbd14af108fea7d4996cdb
4
- data.tar.gz: 7f0e46181747c4f0ee8209496c16a29a81264ccbca39faf1803de6e2a6e3b535
3
+ metadata.gz: 56ace4b5dcb20700d6a42b22cac53d5a2fd7a73db0ce0817352c19ac02653aa1
4
+ data.tar.gz: cbb834ca61e52d95574a4136332ceccfae623a64d438e3fec552dfc9d8250190
5
5
  SHA512:
6
- metadata.gz: e70f6e59b9f9d3de0676dc1d6d6bf2ed7715649fe428e5edb8740247df0b6e12e21b26e2e9361443c80343563160da00841d1e90c35ae906db786aca676645d9
7
- data.tar.gz: 901ca653bdd3c03f9f09086c194c2f60180b693d2b43830335a2d34f39053dfd1e9b974d7f598377493e8121d27cadecdc9ef959b26ca14a186633a6b4dd05b4
6
+ metadata.gz: d652ba346051a94d4b3364047cbe3b6d02048a3dd5bcc911eb6041480d7b2f24f94fd4eaf306fad73e199066da4aafc18b745045da4025d11dec8854924b2aee
7
+ data.tar.gz: 61660f34ee55a04ed35b2f05f94b9f6ffcbacc93abc1666185f06ba66dd9079a6fdbc47f626b51fb859cfaa57d85b55267b222271d7903a60c6afd50d006620a
@@ -12,12 +12,12 @@ jobs:
12
12
  strategy:
13
13
  matrix:
14
14
  container_tag:
15
- - 2.6-bionic
16
15
  - 2.7-bionic
17
16
  - 3.0-focal
17
+ - 3.1-focal
18
18
  protoc_version:
19
- - 3.13.0
20
- - 3.14.0
19
+ - 3.18.2
20
+ - 3.19.4
21
21
  container:
22
22
  image: rubylang/ruby:${{ matrix.container_tag }}
23
23
  steps:
data/.gitignore CHANGED
@@ -7,4 +7,3 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /example/protobuf-gem/
10
- /Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.2.0 (2022-03-18)
4
+
5
+ This is a maintenance release to support the latest version of RBS.
6
+
7
+ * Update to the latest RBS ([#11](https://github.com/square/rbs_protobuf/pull/11))
8
+ * Type check with Steep ([#11](https://github.com/square/rbs_protobuf/pull/11))
9
+ * Drop Ruby 2.6 support ([#11](https://github.com/square/rbs_protobuf/pull/11))
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rbs_protobuf (0.2.0)
5
+ activesupport (>= 4.0)
6
+ rbs (>= 2.2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.0.2.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ ast (2.4.2)
17
+ concurrent-ruby (1.1.9)
18
+ ffi (1.15.5)
19
+ i18n (1.10.0)
20
+ concurrent-ruby (~> 1.0)
21
+ language_server-protocol (3.16.0.3)
22
+ listen (3.7.1)
23
+ rb-fsevent (~> 0.10, >= 0.10.3)
24
+ rb-inotify (~> 0.9, >= 0.9.10)
25
+ middleware (0.1.0)
26
+ minitest (5.15.0)
27
+ parallel (1.21.0)
28
+ parser (3.1.1.0)
29
+ ast (~> 2.4.1)
30
+ protobuf (3.10.5)
31
+ activesupport (>= 3.2)
32
+ middleware
33
+ thor
34
+ thread_safe
35
+ rainbow (3.1.1)
36
+ rake (12.3.3)
37
+ rb-fsevent (0.11.1)
38
+ rb-inotify (0.10.1)
39
+ ffi (~> 1.0)
40
+ rbs (2.2.2)
41
+ steep (0.49.1)
42
+ activesupport (>= 5.1)
43
+ language_server-protocol (>= 3.15, < 4.0)
44
+ listen (~> 3.0)
45
+ parallel (>= 1.0.0)
46
+ parser (>= 3.0)
47
+ rainbow (>= 2.2.2, < 4.0)
48
+ rbs (>= 2.2.0)
49
+ terminal-table (>= 2, < 4)
50
+ terminal-table (3.0.2)
51
+ unicode-display_width (>= 1.1.1, < 3)
52
+ thor (1.2.1)
53
+ thread_safe (0.3.6)
54
+ tzinfo (2.0.4)
55
+ concurrent-ruby (~> 1.0)
56
+ unicode-display_width (2.1.0)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ minitest (~> 5.0)
63
+ protobuf (~> 3.10)
64
+ rake (~> 12.0)
65
+ rbs_protobuf!
66
+ steep
67
+
68
+ BUNDLED WITH
69
+ 2.1.4
data/README.md CHANGED
@@ -20,7 +20,7 @@ message SearchRequest {
20
20
  }
21
21
  ```
22
22
 
23
- rbs_protobuf will generate the following RBS file including method definitions for each attribute with correct types.
23
+ rbs_protobuf will generate the following RBS file including method definitions for each attribute with correct types.
24
24
 
25
25
  ```rbs
26
26
  module Protobuf
@@ -84,28 +84,23 @@ You may need `bundle exec protoc ...` to let bundler set up PATH.
84
84
 
85
85
  ## Type checking
86
86
 
87
- To type check the output, you need to configure your tools to import [gem_rbs_collection](https://github.com/ruby/gem_rbs_collection).
87
+ To type check the output, you need to configure your tools to import [gem_rbs_collection](https://github.com/ruby/gem_rbs_collection) with `rbs collection` command.
88
88
 
89
- $ git submodule add https://github.com/ruby/gem_rbs_collection.git vendor/rbs/gem_rbs_collection
90
-
91
- If you want to validate your RBS files with `rbs validate`, specify `--repo` option.
92
-
93
- $ rbs --repo=vendor/rbs/gem_rbs_collection/gems -rprotobuf validate
94
-
95
- If you want to type check your Ruby program using Steep, add `repo_path` and `library` calls in your `Steepfile`.
96
-
97
- ```ruby
98
- target :app do
99
- repo_path "vendor/rbs/gem_rbs_collection/gems"
100
- library "protobuf"
101
- end
89
+ ```yaml
90
+ # Add the dependency in rbs_collection.yaml
91
+ gems:
92
+ - name: rbs_protobuf
102
93
  ```
103
94
 
95
+ We assume that you don't type check the generated `.pb.rb` code.
96
+ If you want to type check them, you need the definition of `Google::Protobuf`, which can be generated from [`descriptor.proto`](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto).
97
+
104
98
  ### Options
105
99
 
106
100
  * `RBS_PROTOBUF_BACKEND` specifies the Ruby code generator gem. Supported value is `protobuf`. (We will add `google-protobuf` for `google-protobuf` gem.)
107
101
  * `PB_UPCASE_ENUMS` is for `protobuf` gem support. Specify the environment variable to make enum value constants upper case.
108
102
  * `RBS_PROTOBUF_NO_NESTED_NAMESPACE` is to make the RBS declarations flat.
103
+ * `RBS_PROTOBUF_EXTENSION` specifies what to do for extensions.
109
104
 
110
105
  ## Supported features
111
106
 
@@ -116,10 +111,36 @@ end
116
111
  | Packages | ✓ |
117
112
  | Nested messages | ✓ |
118
113
  | Maps | ✓ |
119
- | Extensions | |
114
+ | Extensions | Read next section |
120
115
  | Services | Only generates classes |
121
116
  | Oneof | No support in `protobuf` gem |
122
117
 
118
+ ### Extensions
119
+
120
+ Adding extensions may cause problems if the name of new attribute conflicts.
121
+
122
+ ```proto
123
+ extend SearchRequest {
124
+ // This extension defines an attribute.
125
+ optional string option = 100;
126
+ }
127
+
128
+ extend SearchRequest {
129
+ // Another extension defines another attribute with same name.
130
+ optional string option = 101;
131
+ }
132
+ ```
133
+
134
+ In this case, defining two `option` attributes in RBS causes an error.
135
+ So, rbs_protobuf allows ignoring extensions for this case.
136
+
137
+ You can control the behavior with `RBS_PROTOBUF_EXTENSION` environment variable.
138
+
139
+ * `false`: Ignores extensions.
140
+ * `print`: Prints RBS for extensions instead of writing them to files. You can copy or modify the printed RBS, and put them in some RBS files.
141
+ * Any value else: Generates RBS for extensions.
142
+ * undefined: Ignores extensions but print messages to ask you to specify a value.
143
+
123
144
  ## Development
124
145
 
125
146
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test example:typecheck` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -132,7 +153,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
132
153
 
133
154
  Bug reports and pull requests are welcome on GitHub at https://github.com/square/rbs_protobuf.
134
155
 
135
-
136
156
  ## License
137
157
 
138
158
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ namespace :example do
25
25
  "example/b.proto"
26
26
  )
27
27
  sh(
28
- { "RBS_PROTOBUF_BACKEND" => "protobuf" },
28
+ { "RBS_PROTOBUF_BACKEND" => "protobuf", "RBS_PROTOBUF_EXTENSION" => "true" },
29
29
  "protoc",
30
30
  "--rbs_out=example/protobuf-gem",
31
31
  "-Iexample",
data/Steepfile ADDED
@@ -0,0 +1,21 @@
1
+ D = Steep::Diagnostic
2
+
3
+ target :lib do
4
+ signature "sig"
5
+ check "lib"
6
+
7
+ library "rbs"
8
+ library "monitor"
9
+ library "logger"
10
+ library "set"
11
+ library "json"
12
+ library "tsort"
13
+ library "pathname"
14
+ library "optparse"
15
+ library "rubygems"
16
+
17
+ configure_code_diagnostics do |hash|
18
+ hash[D::Ruby::FallbackAny] = :hint
19
+ hash[D::Ruby::MethodDefinitionMissing] = :hint
20
+ end
21
+ end
data/bin/steep ADDED
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+
3
+ REPO_ROOT=$(cd $(dirname $0); pwd)/..
4
+
5
+ STEEP="bundle exec steep"
6
+
7
+ if type "rbenv" > /dev/null 2>&1; then
8
+ STEEP="rbenv exec ${STEEP}"
9
+ else
10
+ if type "rvm" > /dev/null 2>&1; then
11
+ STEEP="rvm ${REPO_ROOT} do ${STEEP}"
12
+ fi
13
+ fi
14
+
15
+ exec $STEEP $*
data/exe/protoc-gen-rbs CHANGED
@@ -19,11 +19,22 @@ translator = case backend
19
19
  when "protobuf"
20
20
  upcase_enum = ENV.key?("PB_UPCASE_ENUMS")
21
21
  no_nested_namespace = ENV.key?("RBS_PROTOBUF_NO_NESTED_NAMESPACE")
22
+ extension = case ENV["RBS_PROTOBUF_EXTENSION"]
23
+ when "false"
24
+ false
25
+ when nil
26
+ nil
27
+ when "print"
28
+ :print
29
+ else
30
+ true
31
+ end
22
32
 
23
33
  RBSProtobuf::Translator::ProtobufGem.new(
24
34
  input,
25
35
  upcase_enum: upcase_enum,
26
- nested_namespace: !no_nested_namespace
36
+ nested_namespace: !no_nested_namespace,
37
+ extension: extension
27
38
  )
28
39
  when "google-protobuf"
29
40
  raise NotImplementedError
@@ -8,7 +8,7 @@ module RBSProtobuf
8
8
  *path, name = string.delete_prefix("::").split("::").map(&:to_sym)
9
9
 
10
10
  TypeName.new(
11
- name: name,
11
+ name: name || raise,
12
12
  namespace: Namespace.new(path: path, absolute: absolute)
13
13
  )
14
14
  end
@@ -72,7 +72,7 @@ module RBSProtobuf
72
72
  type_name(name)
73
73
  end
74
74
 
75
- Types::Alias.new(name: type_name, location: nil)
75
+ Types::Alias.new(name: type_name, args: [], location: nil)
76
76
  end
77
77
 
78
78
  def function(return_type = Types::Bases::Void.new(location: nil))
@@ -87,7 +87,7 @@ module RBSProtobuf
87
87
  end
88
88
 
89
89
  def block(function, required: true)
90
- MethodType::Block.new(
90
+ Types::Block.new(
91
91
  type: function,
92
92
  required: required
93
93
  )
@@ -98,8 +98,12 @@ module RBSProtobuf
98
98
  end
99
99
 
100
100
  def method_type(params: [], type:, block: nil, location: nil)
101
+ type_params = params.map do |name|
102
+ AST::TypeParam.new(name: name, variance: :invariant, upper_bound: nil, location: nil)
103
+ end
104
+
101
105
  MethodType.new(
102
- type_params: params,
106
+ type_params: type_params,
103
107
  type: type,
104
108
  block: block,
105
109
  location: location
@@ -128,12 +132,8 @@ module RBSProtobuf
128
132
  end
129
133
 
130
134
  def module_type_params(*params)
131
- params.each.with_object(AST::Declarations::ModuleTypeParams.empty) do |param, type_params|
132
- type_params.add(AST::Declarations::ModuleTypeParams::TypeParam.new(
133
- name: param,
134
- variance: :invariant,
135
- skip_validation: false
136
- ))
135
+ params.map do |name|
136
+ AST::TypeParam.new(name: name, variance: :invariant, upper_bound: nil, location: nil)
137
137
  end
138
138
  end
139
139
 
@@ -76,8 +76,7 @@ module RBSProtobuf
76
76
  when FieldDescriptorProto::Type::TYPE_DOUBLE, FieldDescriptorProto::Type::TYPE_FLOAT
77
77
  RBS::BuiltinNames::Float.instance_type
78
78
  when FieldDescriptorProto::Type::TYPE_BOOL
79
- factory.union_type(factory.literal_type(true),
80
- factory.literal_type(false))
79
+ factory.bool_type()
81
80
  else
82
81
  raise "Unknown base type: #{type}"
83
82
  end
@@ -88,6 +87,8 @@ module RBSProtobuf
88
87
 
89
88
  *path, name = string.delete_prefix(".").split(".").map {|s| ActiveSupport::Inflector.upcase_first(s).to_sym }
90
89
 
90
+ name or raise
91
+
91
92
  factory.instance_type(
92
93
  RBS::TypeName.new(
93
94
  name: name,
@@ -1,10 +1,26 @@
1
1
  module RBSProtobuf
2
2
  module Translator
3
3
  class ProtobufGem < Base
4
- def initialize(input, upcase_enum:, nested_namespace:)
4
+ attr_reader :stderr
5
+
6
+ def initialize(input, upcase_enum:, nested_namespace:, extension:, stderr: STDERR)
5
7
  super(input)
6
8
  @upcase_enum = upcase_enum
7
9
  @nested_namespace = nested_namespace
10
+ @extension = extension
11
+ @stderr = stderr
12
+ end
13
+
14
+ def ignore_extension?
15
+ !@extension
16
+ end
17
+
18
+ def print_extension_message?
19
+ @extension == nil
20
+ end
21
+
22
+ def print_extension?
23
+ @extension == :print
8
24
  end
9
25
 
10
26
  def upcase_enum?
@@ -75,11 +91,27 @@ module RBSProtobuf
75
91
  end
76
92
 
77
93
  file.extension.group_by(&:extendee).each.with_index do |(name, extensions), index|
78
- decls.push(*extension_to_decl(name,
79
- extensions,
80
- prefix: RBS::Namespace.root,
81
- source_code_info: source_code_info,
82
- path: [7, index]))
94
+ if ignore_extension?
95
+ if print_extension_message?
96
+ stderr.puts "Extension for `#{name}` ignored in `#{file.name}`; Set RBS_PROTOBUF_EXTENSION env var to generate RBS for extensions."
97
+ end
98
+ else
99
+ exts = extension_to_decl(name,
100
+ extensions,
101
+ prefix: RBS::Namespace.root,
102
+ source_code_info: source_code_info,
103
+ path: [7, index])
104
+
105
+ if print_extension?
106
+ stderr.puts "#=========================================================="
107
+ stderr.puts "# Printing RBS for extensions from #{file.name}"
108
+ stderr.puts "#"
109
+ RBS::Writer.new(out: stderr).write(exts)
110
+ stderr.puts
111
+ else
112
+ decls.push(*exts)
113
+ end
114
+ end
83
115
  end
84
116
 
85
117
  StringIO.new.tap do |io|
@@ -108,12 +140,11 @@ module RBSProtobuf
108
140
 
109
141
  def message_to_decl(message, prefix:, message_path:, source_code_info:, path:)
110
142
  class_name = ActiveSupport::Inflector.upcase_first(message.name)
111
- decl_namespace = prefix.append(class_name.to_sym)
112
143
 
113
144
  RBS::AST::Declarations::Class.new(
114
145
  name: RBS::TypeName.new(name: class_name.to_sym, namespace: prefix),
115
146
  super_class: message_base_class,
116
- type_params: RBS::AST::Declarations::ModuleTypeParams.empty,
147
+ type_params: [],
117
148
  location: nil,
118
149
  comment: comment_for_path(source_code_info, path),
119
150
  members: [],
@@ -401,6 +432,7 @@ module RBSProtobuf
401
432
 
402
433
  enum_decl.members << RBS::AST::Declarations::Alias.new(
403
434
  name: factory.type_name("names"),
435
+ type_params: [],
404
436
  type: factory.union_type(*names),
405
437
  location: nil,
406
438
  comment: nil,
@@ -409,6 +441,7 @@ module RBSProtobuf
409
441
 
410
442
  enum_decl.members << RBS::AST::Declarations::Alias.new(
411
443
  name: factory.type_name("strings"),
444
+ type_params: [],
412
445
  type: factory.union_type(*strings),
413
446
  location: nil,
414
447
  comment: nil,
@@ -417,6 +450,7 @@ module RBSProtobuf
417
450
 
418
451
  enum_decl.members << RBS::AST::Declarations::Alias.new(
419
452
  name: factory.type_name("tags"),
453
+ type_params: [],
420
454
  type: factory.union_type(*tags),
421
455
  location: nil,
422
456
  comment: nil,
@@ -425,6 +459,7 @@ module RBSProtobuf
425
459
 
426
460
  enum_decl.members << RBS::AST::Declarations::Alias.new(
427
461
  name: factory.type_name("values"),
462
+ type_params: [],
428
463
  type: factory.union_type(
429
464
  factory.alias_type("names"),
430
465
  factory.alias_type("strings"),
@@ -460,7 +495,7 @@ module RBSProtobuf
460
495
 
461
496
  enum_decl.members << RBS::AST::Declarations::Constant.new(
462
497
  name: factory.type_name(enum_name(v.name).to_s),
463
- type: RBS::TypeName.new(name: enum_name.to_sym, namespace: prefix),
498
+ type: factory.instance_type(RBS::TypeName.new(name: enum_name.to_sym, namespace: prefix)),
464
499
  comment: comment,
465
500
  location: nil
466
501
  )
@@ -477,7 +512,7 @@ module RBSProtobuf
477
512
  RBS::AST::Declarations::Class.new(
478
513
  name: class_name,
479
514
  super_class: nil,
480
- type_params: RBS::AST::Declarations::ModuleTypeParams.empty,
515
+ type_params: [],
481
516
  location: nil,
482
517
  comment: nil,
483
518
  members: [],
@@ -1,3 +1,3 @@
1
1
  module RBSProtobuf
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/rbs_protobuf.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = "Generate RBS files from .proto files"
11
11
  spec.homepage = "https://github.com/square/rbs_protobuf"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
14
14
 
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
16
  spec.metadata["source_code_uri"] = "https://github.com/square/rbs_protobuf"
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_runtime_dependency "rbs", ">=1.0.4"
28
+ spec.add_runtime_dependency "rbs", ">=2.2.0"
29
29
  spec.add_runtime_dependency "activesupport", ">=4.0"
30
30
  end
@@ -0,0 +1,41 @@
1
+ module RBSProtobuf
2
+ class RBSFactory
3
+ include RBS
4
+
5
+ def type_name: (String) -> RBS::TypeName
6
+
7
+ def namespace: (String) -> RBS::Namespace
8
+
9
+ def instance_type: (String | RBS::TypeName name, *RBS::Types::t args) -> RBS::Types::ClassInstance
10
+
11
+ def singleton_type: (String | RBS::TypeName name) -> RBS::Types::ClassSingleton
12
+
13
+ def union_type: (RBS::Types::t `type`, *RBS::Types::t types) -> RBS::Types::t
14
+
15
+ def nil_type: (?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Bases::Nil
16
+
17
+ def bool_type: (?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Bases::Bool
18
+
19
+ def alias_type: (String | RBS::TypeName name, ?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Alias
20
+
21
+ def function: (?RBS::Types::t return_type) -> RBS::Types::Function
22
+
23
+ def param: (RBS::Types::t type, ?name: Symbol?) -> RBS::Types::Function::Param
24
+
25
+ def block: (RBS::Types::Function function, ?required: bool) -> RBS::Types::Block
26
+
27
+ def untyped: (?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Bases::Any
28
+
29
+ def method_type: (?params: Array[Symbol], type: RBS::Types::Function, ?block: RBS::Types::Block?, ?location: RBS::Location[untyped, untyped]?) -> RBS::MethodType
30
+
31
+ def literal_type: (RBS::Types::Literal::literal) -> RBS::Types::Literal
32
+
33
+ def optional_type: (RBS::Types::t, ?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Optional
34
+
35
+ def type_var: (Symbol name, ?location: RBS::Location[untyped, untyped]?) -> RBS::Types::Variable
36
+
37
+ def module_type_params: (*Symbol params) -> Array[RBS::AST::TypeParam]
38
+
39
+ def unwrap_optional: (RBS::Types::t) -> RBS::Types::t
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ module RBSProtobuf
2
+ module Translator
3
+ class Base
4
+ FieldDescriptorProto: untyped
5
+
6
+ attr_reader input: untyped
7
+
8
+ def initialize: (untyped input) -> void
9
+
10
+ @factory: RBSFactory
11
+
12
+ def factory: () -> RBSFactory
13
+
14
+ @response: untyped
15
+
16
+ def response: () -> untyped
17
+
18
+ def generate_rbs!: () -> void
19
+
20
+ def rbs_name: (String proto_name) -> String
21
+
22
+ def rbs_suffix: () -> ::String
23
+
24
+ def rbs_content: (String file) -> String
25
+
26
+ def comment_for_path: (untyped source_code_info, Array[Integer] path) -> RBS::AST::Comment?
27
+
28
+ def base_type: (untyped `type`) -> RBS::Types::t
29
+
30
+ def message_type: (String) -> RBS::Types::ClassInstance
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,53 @@
1
+ module RBSProtobuf
2
+ module Translator
3
+ class ProtobufGem < Base
4
+ attr_reader stderr: IO
5
+
6
+ def initialize: (
7
+ untyped input,
8
+ upcase_enum: bool,
9
+ nested_namespace: bool,
10
+ extension: bool | :print | nil,
11
+ ?stderr: IO
12
+ ) -> void
13
+
14
+ @upcase_enum: bool
15
+
16
+ @pnested_namespace: bool
17
+
18
+ @extension: bool | :print | nil
19
+
20
+ def ignore_extension?: () -> bool
21
+
22
+ def print_extension_message?: () -> bool
23
+
24
+ def print_extension?: () -> bool
25
+
26
+ def upcase_enum?: () -> bool
27
+
28
+ def nested_namespace?: () -> bool
29
+
30
+ def rbs_content: (untyped file) -> String
31
+
32
+ def message_base_class: () -> RBS::AST::Declarations::Class::Super
33
+
34
+ def repeated_field_type: (RBS::Types::t `type`, ?RBS::Types::t wtype) -> RBS::Types::ClassInstance
35
+
36
+ def message_to_decl: (untyped message, prefix: RBS::Namespace, message_path: untyped, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
37
+
38
+ def field_type: (untyped field, Hash[String, [RBS::Types::t, RBS::Types::t]] maps) -> [RBS::Types::t, RBS::Types::t]
39
+
40
+ def enum_base_class: () -> RBS::AST::Declarations::Class::Super
41
+
42
+ def enum_name: (String name) -> Symbol
43
+
44
+ def enum_type_to_decl: (untyped enum_type, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
45
+
46
+ def extension_to_decl: (String extendee_name, Array[untyped] extensions, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> Array[RBS::AST::Declarations::Class]
47
+
48
+ def service_base_class: () -> RBS::AST::Declarations::Class::Super
49
+
50
+ def service_to_decl: (untyped service, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module RBSProtobuf
2
+ VERSION: String
3
+ end
@@ -0,0 +1,5 @@
1
+ module RBSProtobuf
2
+ attr_reader self.logger: Logger
3
+
4
+ self.@logger: Logger
5
+ end
@@ -0,0 +1,7 @@
1
+ module ActiveSupport
2
+ module Inflector
3
+ def self?.upcase_first: (String) -> String
4
+
5
+ def self?.camelize: (String) -> String
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-10 00:00:00.000000000 Z
11
+ date: 2022-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.4
19
+ version: 2.2.0
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.0.4
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,15 +52,19 @@ files:
52
52
  - ".protoc-version"
53
53
  - ".rakeTasks"
54
54
  - ".travis.yml"
55
+ - CHANGELOG.md
55
56
  - Gemfile
57
+ - Gemfile.lock
56
58
  - LICENSE.txt
57
59
  - README.md
58
60
  - Rakefile
61
+ - Steepfile
59
62
  - bin/console
60
63
  - bin/protoc-gen-dumper
61
64
  - bin/protoc-gen-ruby
62
65
  - bin/rpc_server
63
66
  - bin/setup
67
+ - bin/steep
64
68
  - example/Steepfile
65
69
  - example/a.proto
66
70
  - example/b.proto
@@ -72,6 +76,12 @@ files:
72
76
  - lib/rbs_protobuf/translator/protobuf_gem.rb
73
77
  - lib/rbs_protobuf/version.rb
74
78
  - rbs_protobuf.gemspec
79
+ - sig/rbs_protobuf.rbs
80
+ - sig/rbs_protobuf/rbs_factory.rbs
81
+ - sig/rbs_protobuf/translator/base.rbs
82
+ - sig/rbs_protobuf/translator/protobuf_gem.rbs
83
+ - sig/rbs_protobuf/version.rbs
84
+ - sig/stub/_activesupport.rbs
75
85
  homepage: https://github.com/square/rbs_protobuf
76
86
  licenses:
77
87
  - MIT
@@ -87,14 +97,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
97
  requirements:
88
98
  - - ">="
89
99
  - !ruby/object:Gem::Version
90
- version: 2.3.0
100
+ version: 2.7.0
91
101
  required_rubygems_version: !ruby/object:Gem::Requirement
92
102
  requirements:
93
103
  - - ">="
94
104
  - !ruby/object:Gem::Version
95
105
  version: '0'
96
106
  requirements: []
97
- rubygems_version: 3.2.3
107
+ rubygems_version: 3.3.3
98
108
  signing_key:
99
109
  specification_version: 4
100
110
  summary: Generate RBS files from .proto files