tapioca 0.4.18 → 0.4.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +13 -14
- data/exe/tapioca +2 -0
- data/lib/tapioca/cli/main.rb +11 -1
- data/lib/tapioca/compilers/dsl/active_job.rb +79 -0
- data/lib/tapioca/compilers/dsl/protobuf.rb +132 -16
- data/lib/tapioca/compilers/requires_compiler.rb +1 -1
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +261 -362
- data/lib/tapioca/core_ext/string.rb +18 -0
- data/lib/tapioca/gemfile.rb +24 -4
- data/lib/tapioca/generator.rb +82 -29
- data/lib/tapioca/generic_type_registry.rb +58 -6
- data/lib/tapioca/internal.rb +8 -0
- data/lib/tapioca/rbi/model.rb +405 -0
- data/lib/tapioca/rbi/printer.rb +410 -0
- data/lib/tapioca/rbi/rewriters/group_nodes.rb +106 -0
- data/lib/tapioca/rbi/rewriters/nest_non_public_methods.rb +65 -0
- data/lib/tapioca/rbi/rewriters/nest_singleton_methods.rb +42 -0
- data/lib/tapioca/rbi/rewriters/sort_nodes.rb +82 -0
- data/lib/tapioca/rbi/visitor.rb +21 -0
- data/lib/tapioca/sorbet_ext/fixed_hash_patch.rb +20 -0
- data/lib/tapioca/version.rb +1 -1
- metadata +13 -3
@@ -0,0 +1,65 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Tapioca
|
5
|
+
module RBI
|
6
|
+
module Rewriters
|
7
|
+
class NestNonPublicMethods < Visitor
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
sig { override.params(node: T.nilable(Node)).void }
|
11
|
+
def visit(node)
|
12
|
+
return unless node
|
13
|
+
|
14
|
+
case node
|
15
|
+
when Tree
|
16
|
+
public_group = VisibilityGroup.new(Visibility::Public)
|
17
|
+
protected_group = VisibilityGroup.new(Visibility::Protected)
|
18
|
+
private_group = VisibilityGroup.new(Visibility::Private)
|
19
|
+
|
20
|
+
node.nodes.dup.each do |child|
|
21
|
+
visit(child)
|
22
|
+
next unless child.is_a?(Method)
|
23
|
+
child.detach
|
24
|
+
case child.visibility
|
25
|
+
when Visibility::Protected
|
26
|
+
protected_group << child
|
27
|
+
when Visibility::Private
|
28
|
+
private_group << child
|
29
|
+
else
|
30
|
+
public_group << child
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
node << public_group unless public_group.empty?
|
35
|
+
node << protected_group unless protected_group.empty?
|
36
|
+
node << private_group unless private_group.empty?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Tree
|
43
|
+
extend T::Sig
|
44
|
+
|
45
|
+
sig { void }
|
46
|
+
def nest_non_public_methods!
|
47
|
+
visitor = Rewriters::NestNonPublicMethods.new
|
48
|
+
visitor.visit(self)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class VisibilityGroup < Tree
|
53
|
+
extend T::Sig
|
54
|
+
|
55
|
+
sig { returns(Visibility) }
|
56
|
+
attr_reader :visibility
|
57
|
+
|
58
|
+
sig { params(visibility: Visibility).void }
|
59
|
+
def initialize(visibility)
|
60
|
+
super()
|
61
|
+
@visibility = visibility
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Tapioca
|
5
|
+
module RBI
|
6
|
+
module Rewriters
|
7
|
+
class NestSingletonMethods < Visitor
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
sig { override.params(node: T.nilable(Node)).void }
|
11
|
+
def visit(node)
|
12
|
+
return unless node
|
13
|
+
|
14
|
+
case node
|
15
|
+
when Tree
|
16
|
+
singleton_class = SingletonClass.new
|
17
|
+
|
18
|
+
node.nodes.dup.each do |child|
|
19
|
+
visit(child)
|
20
|
+
next unless child.is_a?(Method) && child.is_singleton
|
21
|
+
child.detach
|
22
|
+
child.is_singleton = false
|
23
|
+
singleton_class << child
|
24
|
+
end
|
25
|
+
|
26
|
+
node << singleton_class unless singleton_class.empty?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Tree
|
33
|
+
extend T::Sig
|
34
|
+
|
35
|
+
sig { void }
|
36
|
+
def nest_singleton_methods!
|
37
|
+
visitor = Rewriters::NestSingletonMethods.new
|
38
|
+
visitor.visit(self)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Tapioca
|
5
|
+
module RBI
|
6
|
+
module Rewriters
|
7
|
+
class SortNodes < Visitor
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
sig { override.params(node: T.nilable(Node)).void }
|
11
|
+
def visit(node)
|
12
|
+
return unless node.is_a?(Tree)
|
13
|
+
visit_all(node.nodes)
|
14
|
+
node.nodes.sort! do |a, b|
|
15
|
+
res = node_rank(a) <=> node_rank(b)
|
16
|
+
res = node_name(a) <=> node_name(b) if res == 0
|
17
|
+
res || 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
sig { params(node: Node).returns(Integer) }
|
24
|
+
def node_rank(node)
|
25
|
+
case node
|
26
|
+
when Group then kind_rank(node.kind)
|
27
|
+
when Include, Extend then 0
|
28
|
+
when Helper then 1
|
29
|
+
when TypeMember then 2
|
30
|
+
when MixesInClassMethods then 3
|
31
|
+
when TStructField then 4
|
32
|
+
when TEnumBlock then 5
|
33
|
+
when Method
|
34
|
+
if node.name == "initialize"
|
35
|
+
7
|
36
|
+
else
|
37
|
+
8
|
38
|
+
end
|
39
|
+
when Scope, Const then 9
|
40
|
+
else
|
41
|
+
10
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
sig { params(kind: Group::Kind).returns(Integer) }
|
46
|
+
def kind_rank(kind)
|
47
|
+
case kind
|
48
|
+
when Group::Kind::Mixins then 0
|
49
|
+
when Group::Kind::Helpers then 1
|
50
|
+
when Group::Kind::TypeMembers then 2
|
51
|
+
when Group::Kind::MixesInClassMethods then 3
|
52
|
+
when Group::Kind::TStructFields then 4
|
53
|
+
when Group::Kind::TEnums then 5
|
54
|
+
when Group::Kind::Inits then 6
|
55
|
+
when Group::Kind::Methods then 7
|
56
|
+
when Group::Kind::Consts then 8
|
57
|
+
else
|
58
|
+
T.absurd(kind)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
sig { params(node: Node).returns(T.nilable(String)) }
|
63
|
+
def node_name(node)
|
64
|
+
case node
|
65
|
+
when Module, Class, Const, Method, Helper, TStructField
|
66
|
+
node.name
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class Tree
|
73
|
+
extend T::Sig
|
74
|
+
|
75
|
+
sig { void }
|
76
|
+
def sort_nodes!
|
77
|
+
visitor = Rewriters::SortNodes.new
|
78
|
+
visitor.visit(self)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Tapioca
|
5
|
+
module RBI
|
6
|
+
class Visitor
|
7
|
+
extend T::Helpers
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
abstract!
|
11
|
+
|
12
|
+
sig { abstract.params(node: T.nilable(Node)).void }
|
13
|
+
def visit(node); end
|
14
|
+
|
15
|
+
sig { params(nodes: T::Array[Node]).void }
|
16
|
+
def visit_all(nodes)
|
17
|
+
nodes.each { |node| visit(node) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module T
|
5
|
+
module Types
|
6
|
+
class FixedHash
|
7
|
+
def name
|
8
|
+
entries = @types.map do |(k, v)|
|
9
|
+
if Symbol === k && ":#{k}" == k.inspect
|
10
|
+
"#{k}: #{v}"
|
11
|
+
else
|
12
|
+
"#{k.inspect} => #{v}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
"{#{entries.join(', ')}}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/tapioca/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tapioca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ufuk Kayserilioglu
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-05-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/tapioca/cli/main.rb
|
129
129
|
- lib/tapioca/compilers/dsl/action_controller_helpers.rb
|
130
130
|
- lib/tapioca/compilers/dsl/action_mailer.rb
|
131
|
+
- lib/tapioca/compilers/dsl/active_job.rb
|
131
132
|
- lib/tapioca/compilers/dsl/active_record_associations.rb
|
132
133
|
- lib/tapioca/compilers/dsl/active_record_columns.rb
|
133
134
|
- lib/tapioca/compilers/dsl/active_record_enum.rb
|
@@ -154,11 +155,20 @@ files:
|
|
154
155
|
- lib/tapioca/config_builder.rb
|
155
156
|
- lib/tapioca/constant_locator.rb
|
156
157
|
- lib/tapioca/core_ext/class.rb
|
158
|
+
- lib/tapioca/core_ext/string.rb
|
157
159
|
- lib/tapioca/gemfile.rb
|
158
160
|
- lib/tapioca/generator.rb
|
159
161
|
- lib/tapioca/generic_type_registry.rb
|
160
162
|
- lib/tapioca/internal.rb
|
161
163
|
- lib/tapioca/loader.rb
|
164
|
+
- lib/tapioca/rbi/model.rb
|
165
|
+
- lib/tapioca/rbi/printer.rb
|
166
|
+
- lib/tapioca/rbi/rewriters/group_nodes.rb
|
167
|
+
- lib/tapioca/rbi/rewriters/nest_non_public_methods.rb
|
168
|
+
- lib/tapioca/rbi/rewriters/nest_singleton_methods.rb
|
169
|
+
- lib/tapioca/rbi/rewriters/sort_nodes.rb
|
170
|
+
- lib/tapioca/rbi/visitor.rb
|
171
|
+
- lib/tapioca/sorbet_ext/fixed_hash_patch.rb
|
162
172
|
- lib/tapioca/sorbet_ext/generic_name_patch.rb
|
163
173
|
- lib/tapioca/sorbet_ext/name_patch.rb
|
164
174
|
- lib/tapioca/version.rb
|
@@ -182,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
192
|
- !ruby/object:Gem::Version
|
183
193
|
version: '0'
|
184
194
|
requirements: []
|
185
|
-
rubygems_version: 3.
|
195
|
+
rubygems_version: 3.2.17
|
186
196
|
signing_key:
|
187
197
|
specification_version: 4
|
188
198
|
summary: A Ruby Interface file generator for gems, core types and the Ruby standard
|