tapioca 0.4.21 → 0.4.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,86 @@
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
+ original_order = node.nodes.map.with_index.to_h
15
+ node.nodes.sort! do |a, b|
16
+ res = node_rank(a) <=> node_rank(b)
17
+ res = node_name(a) <=> node_name(b) if res == 0
18
+ res = (original_order[a] || 0) <=> (original_order[b] || 0) if res == 0
19
+ res || 0
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ sig { params(node: Node).returns(Integer) }
26
+ def node_rank(node)
27
+ case node
28
+ when Group then group_rank(node.kind)
29
+ when Include, Extend then 10
30
+ when Helper then 20
31
+ when TypeMember then 30
32
+ when MixesInClassMethods then 40
33
+ when TStructField then 50
34
+ when TEnumBlock then 60
35
+ when Method
36
+ if node.name == "initialize"
37
+ 71
38
+ elsif !node.is_singleton
39
+ 72
40
+ else
41
+ 73
42
+ end
43
+ when Scope, Const then 80
44
+ else
45
+ 100
46
+ end
47
+ end
48
+
49
+ sig { params(kind: Group::Kind).returns(Integer) }
50
+ def group_rank(kind)
51
+ case kind
52
+ when Group::Kind::Mixins then 0
53
+ when Group::Kind::Helpers then 1
54
+ when Group::Kind::TypeMembers then 2
55
+ when Group::Kind::MixesInClassMethods then 3
56
+ when Group::Kind::TStructFields then 4
57
+ when Group::Kind::TEnums then 5
58
+ when Group::Kind::Inits then 6
59
+ when Group::Kind::Methods then 7
60
+ when Group::Kind::Consts then 8
61
+ else
62
+ T.absurd(kind)
63
+ end
64
+ end
65
+
66
+ sig { params(node: Node).returns(T.nilable(String)) }
67
+ def node_name(node)
68
+ case node
69
+ when Module, Class, Const, Method, Helper, TStructField
70
+ node.name
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ class Tree
77
+ extend T::Sig
78
+
79
+ sig { void }
80
+ def sort_nodes!
81
+ visitor = Rewriters::SortNodes.new
82
+ visitor.visit(self)
83
+ end
84
+ end
85
+ end
86
+ 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
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.4.21"
5
+ VERSION = "0.4.25"
6
6
  end
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.21
4
+ version: 0.4.25
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-04-22 00:00:00.000000000 Z
14
+ date: 2021-08-26 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.0.3
195
+ rubygems_version: 3.2.20
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