orthoses 0.7.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +6 -5
- data/README.md +41 -1
- data/lib/orthoses/attribute.rb +20 -20
- data/lib/orthoses/autoload.rb +37 -0
- data/lib/orthoses/call_tracer.rb +14 -7
- data/lib/orthoses/content/environment.rb +14 -0
- data/lib/orthoses/content/header_builder.rb +12 -7
- data/lib/orthoses/content.rb +5 -5
- data/lib/orthoses/delegate_class.rb +22 -8
- data/lib/orthoses/load_rbs.rb +3 -1
- data/lib/orthoses/mixin.rb +40 -18
- data/lib/orthoses/path_helper.rb +38 -0
- data/lib/orthoses/rbs_prototype_runtime.rb +32 -0
- data/lib/orthoses/utils.rb +9 -4
- data/lib/orthoses/version.rb +1 -1
- data/lib/orthoses.rb +3 -0
- data/sig/orthoses/attribute.rbs +1 -2
- data/sig/orthoses/autoload/hook.rbs +5 -0
- data/sig/orthoses/autoload.rbs +6 -0
- data/sig/orthoses/builder.rbs +2 -2
- data/sig/orthoses/call_tracer/capture.rbs +6 -0
- data/sig/orthoses/call_tracer.rbs +1 -1
- data/sig/orthoses/content/duplication_checker.rbs +3 -4
- data/sig/orthoses/content/environment.rbs +2 -3
- data/sig/orthoses/content/header_builder.rbs +7 -7
- data/sig/orthoses/content.rbs +6 -8
- data/sig/orthoses/delegate_class/hook.rbs +5 -0
- data/sig/orthoses/load_rbs.rbs +3 -2
- data/sig/orthoses/mixin/hook.rbs +9 -0
- data/sig/orthoses/mixin.rbs +4 -2
- data/sig/orthoses/path_helper.rbs +9 -0
- data/sig/orthoses/rbs_prototype_runtime.rbs +6 -0
- data/sig/orthoses/utils.rbs +2 -2
- data/sig/orthoses.rbs +1 -1
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0818d6847c70769b9111a99016d92dff5d4b369485ec5df1752ac847895c077
|
4
|
+
data.tar.gz: d7b7866d290d31836a4fa860662b7abd44da2a4dd79ae0e8f0be4a3aa127cd86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae990a63a96d5d6e4c7a0053203695564451fb709fbcc139cce1d4c6dc8962a10c9bb7b78667be1eccf5dd8ccd69447da97cd011bb58beaa9cacf3dbb951e3ec
|
7
|
+
data.tar.gz: 137f461a5286b3dc9d30c9c71d91fc61f6d948d743f9151b5e9b150dd47cecbe43d6d10073eb29de633bd51f12b3d43afed8ffccf29d52278a035ecbb2757c33
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
orthoses (0.
|
4
|
+
orthoses (0.10.0)
|
5
5
|
rbs (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
listen (3.7.1)
|
22
22
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
23
23
|
rb-inotify (~> 0.9, >= 0.9.10)
|
24
|
-
minitest (5.
|
24
|
+
minitest (5.16.1)
|
25
25
|
parallel (1.22.1)
|
26
26
|
parser (3.1.2.0)
|
27
27
|
ast (~> 2.4.1)
|
@@ -30,14 +30,14 @@ GEM
|
|
30
30
|
rb-fsevent (0.11.1)
|
31
31
|
rb-inotify (0.10.1)
|
32
32
|
ffi (~> 1.0)
|
33
|
-
rbs (2.
|
33
|
+
rbs (2.6.0)
|
34
34
|
rgot (1.1.0)
|
35
|
-
steep (1.0.
|
35
|
+
steep (1.0.1)
|
36
36
|
activesupport (>= 5.1)
|
37
37
|
language_server-protocol (>= 3.15, < 4.0)
|
38
38
|
listen (~> 3.0)
|
39
39
|
parallel (>= 1.0.0)
|
40
|
-
parser (>= 3.
|
40
|
+
parser (>= 3.1)
|
41
41
|
rainbow (>= 2.2.2, < 4.0)
|
42
42
|
rbs (>= 2.3.2)
|
43
43
|
terminal-table (>= 2, < 4)
|
@@ -54,6 +54,7 @@ DEPENDENCIES
|
|
54
54
|
activesupport
|
55
55
|
orthoses!
|
56
56
|
rake (~> 13.0)
|
57
|
+
rbs
|
57
58
|
rgot (~> 1.1)
|
58
59
|
steep
|
59
60
|
|
data/README.md
CHANGED
@@ -41,6 +41,34 @@ Orthoses::Builder.new do
|
|
41
41
|
end.call
|
42
42
|
```
|
43
43
|
|
44
|
+
## Utils
|
45
|
+
|
46
|
+
`Orthoses::Utils` is a collection of useful methods.
|
47
|
+
|
48
|
+
### Orthoses::Utils.each_const_recursive
|
49
|
+
|
50
|
+
Yield const by recursive.
|
51
|
+
|
52
|
+
### Orthoses::Utils.rbs_defined_const?
|
53
|
+
|
54
|
+
Checks if the const name is already defined.
|
55
|
+
|
56
|
+
### Orthoses::Utils.rbs_defined_class?
|
57
|
+
|
58
|
+
Checks if the class name is already defined.
|
59
|
+
|
60
|
+
### Orthoses::Utils.rbs_environment
|
61
|
+
|
62
|
+
Fetch cached `RBS::Environment`.
|
63
|
+
|
64
|
+
### Orthoses::Utils.object_to_rbs
|
65
|
+
|
66
|
+
Convert Ruby object to RBS string.
|
67
|
+
|
68
|
+
### Orthoses::Utils.module_name
|
69
|
+
|
70
|
+
Get true module name by `Module.instance_method(:name).bind(mod).call`.
|
71
|
+
|
44
72
|
## Middlewares
|
45
73
|
|
46
74
|
### Orthoses::Constant
|
@@ -48,10 +76,14 @@ end.call
|
|
48
76
|
Add constant signature to class/module.
|
49
77
|
Signatures are predicted from constant values.
|
50
78
|
|
79
|
+
### Orthoses::Attribute
|
80
|
+
|
81
|
+
Add `attr`, `attr_accessor`, `attr_reader` and `attr_writer` to output RBS.
|
82
|
+
All type set `untyped`.
|
83
|
+
|
51
84
|
### Orthoses::Mixin
|
52
85
|
|
53
86
|
Add module include/extend/prepend definition.
|
54
|
-
It use `Module#{includeed,extended,prepended}` for capture.
|
55
87
|
|
56
88
|
### Orthoses::ObjectSpaceAll
|
57
89
|
|
@@ -115,11 +147,19 @@ Run `rbs prototype rb` command process to `paths` option files.
|
|
115
147
|
`content_filter` option could filter with content decl.
|
116
148
|
`mixin_filter` option could filter with mixin(include, extend, prepend) decl.
|
117
149
|
|
150
|
+
### Orthoses::RBSPrototypeRuntime
|
151
|
+
|
152
|
+
Run `rbs prototype runtime` command process with `patterns` option string.
|
153
|
+
|
118
154
|
### Orthoses::AvoidRecursiveAncestorError
|
119
155
|
|
120
156
|
Mixin a module into an Object class raises `RBS::RecursiveAncestorError` when validation.
|
121
157
|
Please add this middleware then.
|
122
158
|
|
159
|
+
### Orthoses::Autoload
|
160
|
+
|
161
|
+
Force load const defined by `autoload`.
|
162
|
+
|
123
163
|
## Development
|
124
164
|
|
125
165
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/orthoses/attribute.rb
CHANGED
@@ -23,41 +23,40 @@ module Orthoses
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def call
|
26
|
-
Module.prepend(Hook)
|
26
|
+
::Module.prepend(Hook)
|
27
27
|
|
28
28
|
attr = CallTracer.new
|
29
29
|
attr_accessor = CallTracer.new
|
30
30
|
attr_reader = CallTracer.new
|
31
31
|
attr_writer = CallTracer.new
|
32
32
|
|
33
|
-
store = attr.trace(Hook.
|
34
|
-
attr_accessor.trace(Hook.
|
35
|
-
attr_reader.trace(Hook.
|
36
|
-
attr_writer.trace(Hook.
|
33
|
+
store = attr.trace(Hook.instance_method(:attr)) do
|
34
|
+
attr_accessor.trace(Hook.instance_method(:attr_accessor)) do
|
35
|
+
attr_reader.trace(Hook.instance_method(:attr_reader)) do
|
36
|
+
attr_writer.trace(Hook.instance_method(:attr_writer)) do
|
37
37
|
@loader.call
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
attr.result.each do |method, argument|
|
46
|
-
m = method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
43
|
+
attr.captures.each do |capture|
|
44
|
+
m = capture.method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
47
45
|
if m && m[1]
|
48
46
|
receiver_name = m[1]
|
49
47
|
prefix = "self."
|
50
48
|
else
|
51
|
-
receiver_name = Utils.module_name(method.receiver) or next
|
49
|
+
receiver_name = Utils.module_name(capture.method.receiver) or next
|
52
50
|
prefix = nil
|
53
51
|
end
|
54
52
|
content = store[receiver_name]
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
names = capture.argument[:names]
|
54
|
+
if names[1].equal?(true)
|
55
|
+
content << "attr_accessor #{prefix}#{names[0]}: untyped"
|
56
|
+
elsif names[1].equal?(false)
|
57
|
+
content << "attr_reader #{prefix}#{names[0]}: untyped"
|
59
58
|
else
|
60
|
-
|
59
|
+
names.each do |name|
|
61
60
|
content << "attr_reader #{prefix}#{name}: untyped"
|
62
61
|
end
|
63
62
|
end
|
@@ -79,16 +78,17 @@ module Orthoses
|
|
79
78
|
private
|
80
79
|
|
81
80
|
def each_definition(call_tracer)
|
82
|
-
call_tracer.
|
83
|
-
m = method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
81
|
+
call_tracer.captures.each do |capture|
|
82
|
+
m = capture.method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
83
|
+
names = capture.argument[:names]
|
84
84
|
if m && m[1]
|
85
85
|
receiver_name = m[1]
|
86
|
-
|
86
|
+
names.each do |name|
|
87
87
|
yield [receiver_name, "self.#{name}"]
|
88
88
|
end
|
89
89
|
else
|
90
|
-
receiver_name = Utils.module_name(method.receiver) or next
|
91
|
-
|
90
|
+
receiver_name = Utils.module_name(capture.method.receiver) or next
|
91
|
+
names.each do |name|
|
92
92
|
yield [receiver_name, name]
|
93
93
|
end
|
94
94
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Orthoses
|
4
|
+
class Autoload
|
5
|
+
module Hook
|
6
|
+
def autoload(name, path)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(loader)
|
12
|
+
@loader = loader
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
::Module.prepend(Hook)
|
17
|
+
|
18
|
+
autoload = CallTracer.new
|
19
|
+
|
20
|
+
store = autoload.trace(Hook.instance_method(:autoload)) do
|
21
|
+
@loader.call
|
22
|
+
end
|
23
|
+
|
24
|
+
autoload.captures.each do |capture|
|
25
|
+
base_mod = capture.method.receiver
|
26
|
+
name = capture.argument[:name]
|
27
|
+
begin
|
28
|
+
base_mod.const_get(name)
|
29
|
+
rescue NameError, LoadError, ArgumentError => e
|
30
|
+
Orthoses.logger.warn("[Orthoses::Autoload] raise `#{e.message} (#{e.class})` when try to unautoload `#{base_mod}::#{name}`")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
store
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/orthoses/call_tracer.rb
CHANGED
@@ -7,16 +7,19 @@ module Orthoses
|
|
7
7
|
# scope.trace(ActiveRecord::Base.method(:scope)) do
|
8
8
|
# @loader.call
|
9
9
|
# end
|
10
|
-
# scope.
|
11
|
-
# argument[:name]
|
12
|
-
# argument[:body]
|
13
|
-
# argument[:block]
|
10
|
+
# scope.captures.each do |capture|
|
11
|
+
# capture.argument[:name]
|
12
|
+
# capture.argument[:body]
|
13
|
+
# capture.argument[:block]
|
14
14
|
# end
|
15
15
|
class CallTracer
|
16
|
-
|
16
|
+
class Capture < Struct.new(:method, :argument, keyword_init: true)
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :captures
|
17
20
|
|
18
21
|
def initialize
|
19
|
-
@
|
22
|
+
@captures = []
|
20
23
|
end
|
21
24
|
|
22
25
|
def trace(target, &block)
|
@@ -46,7 +49,11 @@ module Orthoses
|
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
49
|
-
|
52
|
+
|
53
|
+
@captures << Capture.new(
|
54
|
+
method: called_method,
|
55
|
+
argument: argument,
|
56
|
+
)
|
50
57
|
end
|
51
58
|
t.enable(target: target, &block)
|
52
59
|
end
|
@@ -86,15 +86,29 @@ module Orthoses
|
|
86
86
|
writer = RBS::Writer.new(out: out)
|
87
87
|
decls.each do |decl|
|
88
88
|
next unless decl.respond_to?(:members)
|
89
|
+
last_visibility = :public
|
89
90
|
decl.members.each do |member|
|
90
91
|
next if member.respond_to?(:members)
|
91
92
|
case member
|
92
93
|
when RBS::AST::Declarations::Constant
|
93
94
|
next unless @constant_filter.nil? || @constant_filter.call(member)
|
95
|
+
when RBS::AST::Members::MethodDefinition
|
96
|
+
if last_visibility == :private && member.kind != :singleton_instance
|
97
|
+
member.instance_variable_set(:@visibility, :private)
|
98
|
+
end
|
94
99
|
when RBS::AST::Members::Mixin
|
95
100
|
next unless @mixin_filter.nil? || @mixin_filter.call(member)
|
96
101
|
when RBS::AST::Members::Attribute
|
97
102
|
next unless @attribute_filter.nil? || @attribute_filter.call(member)
|
103
|
+
if last_visibility == :private
|
104
|
+
member.instance_variable_set(:@visibility, :private)
|
105
|
+
end
|
106
|
+
when RBS::AST::Members::Public
|
107
|
+
last_visibility = :public
|
108
|
+
next
|
109
|
+
when RBS::AST::Members::Private
|
110
|
+
last_visibility = :private
|
111
|
+
next
|
98
112
|
end
|
99
113
|
writer.write_member(member)
|
100
114
|
end
|
@@ -43,13 +43,9 @@ module Orthoses
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def build_super_class(primary)
|
46
|
-
return nil if primary.decl.super_class.then { |s| s.nil? || s.name.relative!.to_s.then { |n| n == "Object" || n == "Random::Base" } }
|
47
|
-
|
48
|
-
context = primary.outer.length.times.map do |i|
|
49
|
-
primary.outer[0, i + 1].map(&:name).inject(:+).to_namespace.absolute!
|
50
|
-
end
|
51
|
-
context.push(RBS::Namespace.root)
|
46
|
+
return nil if primary.decl.super_class.then { |s| s.nil? || s.name.relative!.to_s.then { |n| n == "Object" || n == "Random::Base" || n.start_with?("RBS::Unnamed") } }
|
52
47
|
|
48
|
+
context = build_context(entry: primary)
|
53
49
|
super_class_name = @resolver.resolve(primary.decl.super_class.name, context: context) || primary.decl.super_class.name
|
54
50
|
if primary.decl.super_class.args.empty?
|
55
51
|
if super_class_entry = @env.class_decls[super_class_name]
|
@@ -65,7 +61,16 @@ module Orthoses
|
|
65
61
|
|
66
62
|
def build_interface(entry:, name_hint: nil)
|
67
63
|
full_name = name_hint || entry.decl.name.relative!
|
68
|
-
|
64
|
+
context = build_context(entry: entry)
|
65
|
+
resolved_name = @resolver.resolve(full_name, context: context) || full_name
|
66
|
+
"interface #{name_and_params(resolved_name.relative!, entry.decl.type_params)}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_context(entry:)
|
70
|
+
context = entry.outer.length.times.map do |i|
|
71
|
+
entry.outer[0, i + 1].map(&:name).inject(:+).to_namespace.absolute!
|
72
|
+
end
|
73
|
+
context.push(RBS::Namespace.root)
|
69
74
|
end
|
70
75
|
|
71
76
|
def name_and_params(name, params)
|
data/lib/orthoses/content.rb
CHANGED
@@ -81,11 +81,6 @@ module Orthoses
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def auto_header
|
84
|
-
if name.split('::').last.start_with?('_')
|
85
|
-
self.header = "interface #{name}"
|
86
|
-
return
|
87
|
-
end
|
88
|
-
|
89
84
|
env = Utils.rbs_environment(collection: true)
|
90
85
|
if entry = env.class_decls[TypeName(name).absolute!]
|
91
86
|
@header = Content::HeaderBuilder.new(env: env).build(entry: entry)
|
@@ -94,6 +89,11 @@ module Orthoses
|
|
94
89
|
|
95
90
|
return unless @header.nil?
|
96
91
|
|
92
|
+
if name.split('::').last.start_with?('_')
|
93
|
+
self.header = "interface #{name}"
|
94
|
+
return
|
95
|
+
end
|
96
|
+
|
97
97
|
val = Object.const_get(name)
|
98
98
|
|
99
99
|
case val
|
@@ -2,31 +2,44 @@
|
|
2
2
|
|
3
3
|
module Orthoses
|
4
4
|
class DelegateClass
|
5
|
+
module Hook
|
6
|
+
def inherited(subclass)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
def initialize(loader)
|
6
12
|
@loader = loader
|
7
13
|
end
|
8
14
|
|
9
15
|
def call
|
10
16
|
require 'delegate'
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
+
::Class.prepend(Hook)
|
18
|
+
|
19
|
+
inherited = CallTracer.new
|
20
|
+
|
17
21
|
delegate_class_super_map = {}
|
18
22
|
delegate_class_tracer = TracePoint.new(:return) do |tp|
|
19
23
|
return_value = tp.return_value
|
20
24
|
superclass = tp.binding.local_variable_get(:superclass)
|
21
25
|
delegate_class_super_map[return_value] = superclass
|
22
26
|
end
|
27
|
+
|
23
28
|
store = delegate_class_tracer.enable(target: method(:DelegateClass)) do
|
24
|
-
|
29
|
+
inherited.trace(Hook.instance_method(:inherited)) do
|
30
|
+
@loader.call
|
31
|
+
end
|
25
32
|
end
|
26
|
-
|
33
|
+
|
34
|
+
store["Class"].body.delete("prepend Orthoses::DelegateClass::Hook")
|
35
|
+
|
36
|
+
inherited.captures.each do |capture|
|
37
|
+
superclass = capture.method.receiver
|
27
38
|
if delegate_to_class = delegate_class_super_map[superclass]
|
39
|
+
subclass = capture.argument[:subclass]
|
28
40
|
subclass_name = Utils.module_name(subclass)
|
29
41
|
next unless subclass_name
|
42
|
+
|
30
43
|
delegate_to_class_name = Utils.module_name(delegate_to_class)
|
31
44
|
next unless delegate_to_class_name
|
32
45
|
|
@@ -34,6 +47,7 @@ module Orthoses
|
|
34
47
|
store[subclass_name].header = header
|
35
48
|
end
|
36
49
|
end
|
50
|
+
|
37
51
|
store
|
38
52
|
end
|
39
53
|
|
data/lib/orthoses/load_rbs.rb
CHANGED
@@ -11,7 +11,9 @@ module Orthoses
|
|
11
11
|
|
12
12
|
def call
|
13
13
|
@loader.call.tap do |store|
|
14
|
-
|
14
|
+
paths = @paths
|
15
|
+
paths = paths.call if paths.instance_of?(Proc)
|
16
|
+
env = Content::Environment.load_from_paths(paths.to_a)
|
15
17
|
env.write_to(store: store)
|
16
18
|
end
|
17
19
|
end
|
data/lib/orthoses/mixin.rb
CHANGED
@@ -2,49 +2,71 @@
|
|
2
2
|
|
3
3
|
module Orthoses
|
4
4
|
class Mixin
|
5
|
+
module Hook
|
6
|
+
def include(*modules)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
def extend(*modules)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
def prepend(*modules)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
5
17
|
def initialize(loader, if: nil)
|
6
18
|
@loader = loader
|
7
19
|
@if = binding.local_variable_get(:if)
|
8
20
|
end
|
9
21
|
|
10
22
|
def call
|
11
|
-
|
12
|
-
::Module.module_eval do
|
13
|
-
define_method(:included) do |mod|
|
14
|
-
modules[mod] << [:include, self]
|
15
|
-
end
|
23
|
+
::Module.prepend(Hook)
|
16
24
|
|
17
|
-
|
18
|
-
|
19
|
-
|
25
|
+
include = CallTracer.new
|
26
|
+
extend = CallTracer.new
|
27
|
+
prepend = CallTracer.new
|
20
28
|
|
21
|
-
|
22
|
-
|
29
|
+
store = include.trace(Hook.instance_method(:include)) do
|
30
|
+
extend.trace(Hook.instance_method(:extend)) do
|
31
|
+
prepend.trace(Hook.instance_method(:prepend)) do
|
32
|
+
@loader.call
|
33
|
+
end
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
26
|
-
store
|
37
|
+
collect_definitions(store, include, :include)
|
38
|
+
collect_definitions(store, extend, :extend)
|
39
|
+
collect_definitions(store, prepend, :prepend)
|
40
|
+
|
41
|
+
store
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
27
45
|
|
28
|
-
|
46
|
+
def collect_definitions(store, call_tracer, how)
|
47
|
+
call_tracer.captures.each do |capture|
|
48
|
+
base_mod = capture.method.receiver
|
29
49
|
next unless base_mod.kind_of?(Module)
|
50
|
+
|
30
51
|
base_mod_name = Utils.module_name(base_mod)
|
31
52
|
next unless base_mod_name
|
32
53
|
|
33
|
-
|
54
|
+
content = store[base_mod_name]
|
55
|
+
capture.argument[:modules].each do |mod|
|
34
56
|
mod_name = Utils.module_name(mod)
|
35
57
|
next unless mod_name
|
58
|
+
|
59
|
+
next if mod_name.start_with?("Orthoses")
|
60
|
+
|
36
61
|
known_type_params = Utils.known_type_params(mod)
|
37
62
|
next unless known_type_params.nil? || known_type_params.empty?
|
63
|
+
|
38
64
|
next unless @if.nil? || @if.call(base_mod, how, mod)
|
39
65
|
|
40
66
|
store[mod_name]
|
41
|
-
|
42
|
-
"#{how} #{mod_name}"
|
67
|
+
content << "#{how} #{mod_name}"
|
43
68
|
end
|
44
|
-
store[base_mod_name].concat(lines)
|
45
69
|
end
|
46
|
-
|
47
|
-
store
|
48
70
|
end
|
49
71
|
end
|
50
72
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Helper for find best version dir.
|
4
|
+
# Orthoses::PathHelper.best_version_paths(
|
5
|
+
# ::ActiveSupport::VERSION::STRING,
|
6
|
+
# "known_sig/activesupport")
|
7
|
+
module Orthoses
|
8
|
+
class PathHelper
|
9
|
+
class << self
|
10
|
+
def best_version_paths(current, base_dir)
|
11
|
+
new(current, base_dir).best_version_paths
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(current, base_dir)
|
16
|
+
@current = current
|
17
|
+
@base_dir = base_dir
|
18
|
+
end
|
19
|
+
|
20
|
+
def best_version_paths
|
21
|
+
best_version = find_best_version
|
22
|
+
Dir.glob("#{@base_dir}/#{best_version}/**/*.rbs")
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_best_version
|
26
|
+
current_v = Gem::Version.new(@current)
|
27
|
+
versions = version_dir
|
28
|
+
versions.reverse.bsearch { |v| v <= current_v } || versions.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def version_dir
|
32
|
+
Dir.glob("#{@base_dir}/*")
|
33
|
+
.map(&File.method(:basename))
|
34
|
+
.map(&Gem::Version.method(:new))
|
35
|
+
.sort
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Orthoses
|
2
|
+
# Call `rbs prototype runtime` and add to store
|
3
|
+
# use Orthoses::RBSPrototypeRuntime,
|
4
|
+
# patterns: ['Foo::*']
|
5
|
+
class RBSPrototypeRuntime
|
6
|
+
def initialize(loader, patterns:)
|
7
|
+
@loader = loader
|
8
|
+
@patterns = patterns
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
@loader.call.tap do |store|
|
13
|
+
content_env = Orthoses::Content::Environment.new
|
14
|
+
|
15
|
+
patterns = @patterns
|
16
|
+
env = RBS::Environment.new
|
17
|
+
merge = true
|
18
|
+
owners_included = []
|
19
|
+
RBS::Prototype::Runtime.new(
|
20
|
+
patterns: patterns,
|
21
|
+
env: env,
|
22
|
+
merge: merge,
|
23
|
+
owners_included: owners_included,
|
24
|
+
).decls.each do |decl|
|
25
|
+
content_env << decl
|
26
|
+
end
|
27
|
+
|
28
|
+
content_env.write_to(store: store)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/orthoses/utils.rb
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
module Orthoses
|
4
4
|
module Utils
|
5
5
|
def self.unautoload!
|
6
|
+
warn "`Orthoses::Utils.unautoload!` is deprecated. please use `Orthoses::Autoload` middleware instead."
|
6
7
|
ObjectSpace.each_object(Module) do |mod|
|
7
8
|
each_const_recursive(mod)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.each_const_recursive(root, cache: {}, on_error: nil, &block)
|
12
|
-
root.constants(false).each do |const|
|
13
|
+
root.constants(false).sort.each do |const|
|
13
14
|
val = root.const_get(const)
|
14
15
|
next if cache[const].equal?(val)
|
15
16
|
cache[const] = val
|
@@ -101,12 +102,16 @@ module Orthoses
|
|
101
102
|
def self.object_to_rbs(object, strict:)
|
102
103
|
case object
|
103
104
|
when Class, Module
|
104
|
-
|
105
|
+
if name = module_name(object)
|
106
|
+
"singleton(#{name})"
|
107
|
+
else
|
108
|
+
"untyped"
|
109
|
+
end
|
105
110
|
when Integer, Symbol, String
|
106
111
|
if strict
|
107
112
|
object.inspect
|
108
113
|
else
|
109
|
-
|
114
|
+
module_name(object.class) || 'untyped'
|
110
115
|
end
|
111
116
|
when true, false, nil
|
112
117
|
object.inspect
|
@@ -151,7 +156,7 @@ module Orthoses
|
|
151
156
|
# see also https://github.com/ruby/rbs/pull/975
|
152
157
|
'untyped'
|
153
158
|
else
|
154
|
-
|
159
|
+
module_name(object.class) || 'untyped'
|
155
160
|
end
|
156
161
|
end
|
157
162
|
|
data/lib/orthoses/version.rb
CHANGED
data/lib/orthoses.rb
CHANGED
@@ -15,10 +15,13 @@ require_relative 'orthoses/filter'
|
|
15
15
|
require_relative 'orthoses/mixin'
|
16
16
|
require_relative 'orthoses/load_rbs'
|
17
17
|
require_relative 'orthoses/object_space_all'
|
18
|
+
require_relative 'orthoses/path_helper'
|
18
19
|
require_relative 'orthoses/pp'
|
19
20
|
require_relative 'orthoses/rbs_prototype_rb'
|
21
|
+
require_relative 'orthoses/rbs_prototype_runtime'
|
20
22
|
require_relative 'orthoses/store'
|
21
23
|
require_relative 'orthoses/tap'
|
24
|
+
require_relative 'orthoses/autoload'
|
22
25
|
require_relative 'orthoses/utils'
|
23
26
|
require_relative 'orthoses/version'
|
24
27
|
require_relative 'orthoses/walk'
|
data/sig/orthoses/attribute.rbs
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
class Orthoses::Attribute
|
4
4
|
def initialize: (Orthoses::_Call loader) -> void
|
5
5
|
def call: () -> Orthoses::store
|
6
|
-
private
|
7
|
-
def each_definition: (untyped call_tracer) { (untyped) -> untyped } -> untyped
|
6
|
+
private def each_definition: (untyped call_tracer) { (untyped) -> untyped } -> untyped
|
8
7
|
@loader: Orthoses::_Call
|
9
8
|
end
|
data/sig/orthoses/builder.rbs
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
3
|
class Orthoses::Builder
|
4
|
-
def initialize: () { () -> untyped } -> void
|
5
|
-
def use: (untyped middleware, *untyped args, **untyped key) { () -> untyped } -> untyped
|
4
|
+
def initialize: () ?{ () -> untyped } -> void
|
5
|
+
def use: (untyped middleware, *untyped args, **untyped key) ?{ () -> untyped } -> untyped
|
6
6
|
def run: (untyped loader) -> untyped
|
7
7
|
def to_loader: () -> untyped
|
8
8
|
|
@@ -3,8 +3,7 @@
|
|
3
3
|
class Orthoses::Content::DuplicationChecker
|
4
4
|
def initialize: (untyped decl) -> void
|
5
5
|
def update_decl: () -> untyped
|
6
|
-
private
|
7
|
-
def
|
8
|
-
def
|
9
|
-
def member_key: (untyped member) -> untyped
|
6
|
+
private def drop_known_method_definition: (untyped uniq_map) -> untyped
|
7
|
+
private def member_to_s: (untyped member) -> untyped
|
8
|
+
private def member_key: (untyped member) -> untyped
|
10
9
|
end
|
@@ -7,12 +7,11 @@ class Orthoses::Content::Environment
|
|
7
7
|
def <<: (RBS::AST::Declarations::t decl) -> RBS::Environment
|
8
8
|
def write_to: (store: Orthoses::store) -> void
|
9
9
|
def each: () { (Orthoses::Content) -> void } -> void
|
10
|
-
private
|
11
10
|
# Avoid `RBS::GenericParameterMismatchError` from like rbs_prototype_rb
|
12
11
|
# class Array # <= RBS::GenericParameterMismatchError
|
13
12
|
# end
|
14
|
-
def avoid_generic_parameter_mismatch_error: () -> untyped
|
15
|
-
def decls_to_lines: (untyped decls) -> untyped
|
13
|
+
private def avoid_generic_parameter_mismatch_error: () -> untyped
|
14
|
+
private def decls_to_lines: (untyped decls) -> untyped
|
16
15
|
type constant_filter = ^(RBS::AST::Declarations::Constant) -> boolish
|
17
16
|
type mixin_filter = ^(RBS::AST::Members::Mixin) -> boolish
|
18
17
|
type attribute_filter = ^(RBS::AST::Members::Attribute) -> boolish
|
@@ -3,11 +3,11 @@
|
|
3
3
|
class Orthoses::Content::HeaderBuilder
|
4
4
|
def initialize: (env: untyped) -> void
|
5
5
|
def build: (entry: untyped, ?name_hint: untyped?) -> untyped
|
6
|
-
private
|
7
|
-
def
|
8
|
-
def
|
9
|
-
def
|
10
|
-
def
|
11
|
-
def name_and_params: (untyped name, untyped params) -> ::String
|
12
|
-
def name_and_args: (untyped name, untyped args) -> (::String | nil)
|
6
|
+
private def build_module: (entry: untyped, ?name_hint: untyped?) -> ::String
|
7
|
+
private def build_class: (entry: untyped, ?name_hint: untyped?) -> ::String
|
8
|
+
private def build_super_class: (untyped primary) -> (nil | untyped)
|
9
|
+
private def build_interface: (entry: untyped, ?name_hint: untyped?) -> ::String
|
10
|
+
private def build_context: (entry: untyped) -> untyped
|
11
|
+
private def name_and_params: (untyped name, untyped params) -> ::String
|
12
|
+
private def name_and_args: (untyped name, untyped args) -> (::String | nil)
|
13
13
|
end
|
data/sig/orthoses/content.rbs
CHANGED
@@ -6,15 +6,13 @@ class Orthoses::Content
|
|
6
6
|
def concat: (Array[String]) -> void
|
7
7
|
def to_rbs: () -> String
|
8
8
|
def to_decl: () -> untyped
|
9
|
+
private def original_rbs: () -> ::String
|
9
10
|
|
10
|
-
private
|
11
|
-
def
|
12
|
-
|
13
|
-
def
|
14
|
-
def
|
15
|
-
def auto_header: () -> (nil | untyped)
|
16
|
-
def temporary_type_params: (untyped name) -> untyped
|
17
|
-
def type_params: (untyped name) -> untyped
|
11
|
+
private def uniqed_body_string: () -> String
|
12
|
+
private def uniqed_body_decl: () -> RBS::AST::Declarations::t
|
13
|
+
private def auto_header: () -> (nil | untyped)
|
14
|
+
private def temporary_type_params: (untyped name) -> untyped
|
15
|
+
private def type_params: (untyped name) -> untyped
|
18
16
|
attr_reader name: String
|
19
17
|
attr_reader body: Array[String]
|
20
18
|
attr_accessor header: String?
|
data/sig/orthoses/load_rbs.rbs
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
3
|
class Orthoses::LoadRBS
|
4
|
-
def initialize: (Orthoses::_Call loader, paths:
|
4
|
+
def initialize: (Orthoses::_Call loader, paths: paths) -> void
|
5
5
|
def call: () -> Orthoses::store
|
6
|
+
type paths = Array[String] | ^() -> Array[String]
|
6
7
|
@loader: Orthoses::_Call
|
7
|
-
@paths:
|
8
|
+
@paths: paths
|
8
9
|
end
|
data/sig/orthoses/mixin.rbs
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
3
|
class Orthoses::Mixin
|
4
|
-
def initialize: (
|
5
|
-
def call: () ->
|
4
|
+
def initialize: (Orthoses::_Call loader) -> void
|
5
|
+
def call: () -> Orthoses::store
|
6
|
+
private def collect_definitions: (Orthoses::store store, Orthoses::CallTracer call_tracer, :include | :extend | :prepend how) -> void
|
7
|
+
@loader: Orthoses::_Call
|
6
8
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
|
+
|
3
|
+
class Orthoses::PathHelper
|
4
|
+
def self.best_version_paths: (untyped current, untyped base_dir) -> untyped
|
5
|
+
def initialize: (untyped current, untyped base_dir) -> void
|
6
|
+
def best_version_paths: () -> untyped
|
7
|
+
def find_best_version: () -> untyped
|
8
|
+
def version_dir: () -> untyped
|
9
|
+
end
|
data/sig/orthoses/utils.rbs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
3
|
module Orthoses::Utils
|
4
|
-
def self.unautoload!: () ->
|
4
|
+
def self.unautoload!: () -> untyped
|
5
5
|
|
6
6
|
def self.each_const_recursive: (Module root, ?cache: Hash[untyped, true], ?on_error: ^(Orthoses::ConstLoadError) -> void) ?{ (Module, Symbol, untyped) -> void } -> void
|
7
7
|
|
@@ -19,7 +19,7 @@ module Orthoses::Utils
|
|
19
19
|
|
20
20
|
def self.module_to_type_name: (Module) -> RBS::TypeName?
|
21
21
|
|
22
|
-
def self.known_type_params: (Module | String) -> Array[RBS::AST::TypeParam]
|
22
|
+
def self.known_type_params: (Module | String) -> Array[RBS::AST::TypeParam]?
|
23
23
|
|
24
24
|
def self.new_store: () -> Orthoses::store
|
25
25
|
|
data/sig/orthoses.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orthoses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- examples/simple_middleware.rbs
|
42
42
|
- lib/orthoses.rb
|
43
43
|
- lib/orthoses/attribute.rb
|
44
|
+
- lib/orthoses/autoload.rb
|
44
45
|
- lib/orthoses/avoid_recursive_ancestor_error.rb
|
45
46
|
- lib/orthoses/builder.rb
|
46
47
|
- lib/orthoses/call_tracer.rb
|
@@ -55,8 +56,10 @@ files:
|
|
55
56
|
- lib/orthoses/load_rbs.rb
|
56
57
|
- lib/orthoses/mixin.rb
|
57
58
|
- lib/orthoses/object_space_all.rb
|
59
|
+
- lib/orthoses/path_helper.rb
|
58
60
|
- lib/orthoses/pp.rb
|
59
61
|
- lib/orthoses/rbs_prototype_rb.rb
|
62
|
+
- lib/orthoses/rbs_prototype_runtime.rb
|
60
63
|
- lib/orthoses/store.rb
|
61
64
|
- lib/orthoses/tap.rb
|
62
65
|
- lib/orthoses/utils.rb
|
@@ -69,10 +72,13 @@ files:
|
|
69
72
|
- sig/orthoses/_middle_ware.rbs
|
70
73
|
- sig/orthoses/attribute.rbs
|
71
74
|
- sig/orthoses/attribute/hook.rbs
|
75
|
+
- sig/orthoses/autoload.rbs
|
76
|
+
- sig/orthoses/autoload/hook.rbs
|
72
77
|
- sig/orthoses/avoid_recursive_ancestor_error.rbs
|
73
78
|
- sig/orthoses/builder.rbs
|
74
79
|
- sig/orthoses/builder/call_logable.rbs
|
75
80
|
- sig/orthoses/call_tracer.rbs
|
81
|
+
- sig/orthoses/call_tracer/capture.rbs
|
76
82
|
- sig/orthoses/const_load_error.rbs
|
77
83
|
- sig/orthoses/constant.rbs
|
78
84
|
- sig/orthoses/content.rbs
|
@@ -81,13 +87,17 @@ files:
|
|
81
87
|
- sig/orthoses/content/header_builder.rbs
|
82
88
|
- sig/orthoses/create_file_by_name.rbs
|
83
89
|
- sig/orthoses/delegate_class.rbs
|
90
|
+
- sig/orthoses/delegate_class/hook.rbs
|
84
91
|
- sig/orthoses/filter.rbs
|
85
92
|
- sig/orthoses/load_rbs.rbs
|
86
93
|
- sig/orthoses/mixin.rbs
|
94
|
+
- sig/orthoses/mixin/hook.rbs
|
87
95
|
- sig/orthoses/name_space_error.rbs
|
88
96
|
- sig/orthoses/object_space_all.rbs
|
97
|
+
- sig/orthoses/path_helper.rbs
|
89
98
|
- sig/orthoses/pp.rbs
|
90
99
|
- sig/orthoses/rbs_prototype_rb.rbs
|
100
|
+
- sig/orthoses/rbs_prototype_runtime.rbs
|
91
101
|
- sig/orthoses/store.rbs
|
92
102
|
- sig/orthoses/tap.rbs
|
93
103
|
- sig/orthoses/utils.rbs
|
@@ -114,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
124
|
- !ruby/object:Gem::Version
|
115
125
|
version: '0'
|
116
126
|
requirements: []
|
117
|
-
rubygems_version: 3.3.
|
127
|
+
rubygems_version: 3.3.16
|
118
128
|
signing_key:
|
119
129
|
specification_version: 4
|
120
130
|
summary: Framework for Generate RBS
|