orthoses 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +6 -1
- data/Gemfile.lock +35 -22
- data/examples/rack-test/Gemfile.lock +3 -3
- data/examples/rack-test/out/rack/test/cookie.rbs +28 -0
- data/examples/rack-test/out/rack/test/cookie_jar.rbs +28 -0
- data/examples/rack-test/out/rack/test/fake_app.rbs +13 -0
- data/examples/rack-test/out/rack/test/input_rewinder.rbs +8 -0
- data/examples/rack-test/out/rack/test/methods.rbs +98 -0
- data/examples/rack-test/out/rack/test/session.rbs +186 -0
- data/examples/rack-test/out/rack/test/uploaded_file.rbs +18 -0
- data/examples/rack-test/out/rack/test/utils.rbs +112 -0
- data/examples/rack-test/out/rack/test.rbs +3 -0
- data/lib/orthoses/call_tracer/lazy.rb +12 -0
- data/lib/orthoses/content/duplication_checker.rb +40 -18
- data/lib/orthoses/content/environment.rb +17 -3
- data/lib/orthoses/content/header_builder.rb +4 -5
- data/lib/orthoses/content.rb +47 -45
- data/lib/orthoses/filter.rb +2 -2
- data/lib/orthoses/rbs_prototype_rb.rb +16 -2
- data/lib/orthoses/trace/method.rb +7 -2
- data/lib/orthoses/utils.rb +9 -25
- data/lib/orthoses/version.rb +1 -1
- data/orthoses.gemspec +1 -1
- data/sig/orthoses/builder.rbs +9 -0
- data/sig/orthoses/call_tracer/capture.rbs +1 -1
- data/sig/orthoses/call_tracer/lazy.rbs +14 -1
- data/sig/orthoses/call_tracer.rbs +1 -1
- data/sig/orthoses/content/duplication_checker.rbs +3 -0
- data/sig/orthoses/content/header_builder.rbs +1 -0
- data/sig/orthoses/content.rbs +1 -1
- data/sig/orthoses/filter.rbs +5 -0
- data/sig/orthoses/lazy_trace_point.rbs +9 -1
- data/sig/orthoses/outputable/avoid_recursive_ancestor_error.rbs +2 -0
- data/sig/orthoses/outputable/constantizable_filter.rbs +2 -0
- data/sig/orthoses/outputable/uniq_content_body.rbs +2 -0
- data/sig/orthoses/pp.rbs +2 -0
- data/sig/orthoses/rbs_prototype_rb.rbs +5 -0
- data/sig/orthoses/rbs_prototype_runtime.rbs +3 -0
- data/sig/orthoses/sort.rbs +1 -0
- data/sig/orthoses/store.rbs +2 -0
- data/sig/orthoses/tap.rbs +3 -0
- data/sig/orthoses/utils/type_list.rbs +1 -0
- data/sig/orthoses/utils.rbs +0 -2
- data/sig/orthoses.rbs +1 -1
- metadata +14 -5
@@ -0,0 +1,112 @@
|
|
1
|
+
module Rack::Test::Utils
|
2
|
+
def build_nested_query: (Hash[Symbol, Hash[Symbol, Array[Integer]]] value, ?nil prefix) -> String
|
3
|
+
| (Hash[Symbol, Array[Integer]] value, ?String prefix) -> String
|
4
|
+
| (Array[Integer] value, ?String prefix) -> String
|
5
|
+
| (Integer value, ?String prefix) -> String
|
6
|
+
| (Hash[Symbol, nil] value, ?nil prefix) -> String
|
7
|
+
| (nil value, ?String prefix) -> String
|
8
|
+
| (Hash[Symbol, Integer] value, ?nil prefix) -> String
|
9
|
+
| (Hash[String, Array[Integer]] value, ?nil prefix) -> String
|
10
|
+
| (nil value, ?nil prefix) -> String
|
11
|
+
| (Hash[Symbol, Array[Integer]] value, ?nil prefix) -> String
|
12
|
+
| (Hash[Symbol, Hash[Symbol, Integer]] value, ?nil prefix) -> String
|
13
|
+
| (Hash[Symbol, Integer] value, ?String prefix) -> String
|
14
|
+
| (Hash[Symbol, Array[untyped]] value, ?nil prefix) -> String
|
15
|
+
| (Array[untyped] value, ?String prefix) -> String
|
16
|
+
| (String value, ?nil prefix) -> String
|
17
|
+
| (Hash[Symbol, Array[Hash[Symbol, Integer]]] value, ?nil prefix) -> String
|
18
|
+
| (Array[Hash[Symbol, Integer]] value, ?String prefix) -> String
|
19
|
+
| (Hash[untyped, untyped] value, ?nil prefix) -> String
|
20
|
+
| (Hash[Symbol, String] value, ?nil prefix) -> String
|
21
|
+
| (String value, ?String prefix) -> String
|
22
|
+
| (Hash[String, String] value, ?nil prefix) -> String
|
23
|
+
| (Hash[String, Hash[String, String]] value, ?nil prefix) -> String
|
24
|
+
| (Hash[String, String] value, ?String prefix) -> String
|
25
|
+
| (Hash[Symbol, Hash[Symbol, String]] value, ?nil prefix) -> String
|
26
|
+
| (Hash[Symbol, String] value, ?String prefix) -> String
|
27
|
+
|
28
|
+
def build_multipart: (Hash[untyped, untyped] params, ?bool _first, ?bool multipart) -> nil
|
29
|
+
| (Hash[Symbol, String] params, ?bool _first, ?bool multipart) -> nil
|
30
|
+
| (Hash[String, String] params, ?bool _first, ?bool multipart) -> String?
|
31
|
+
| (Hash[String, Array[Rack::Test::UploadedFile]] params, ?bool _first, ?bool multipart) -> bool
|
32
|
+
| (Hash[Symbol, Hash[Symbol, String]] params, ?bool _first, ?bool multipart) -> nil
|
33
|
+
| (Hash[String, Hash[String, Hash[String, String]] | Rack::Test::UploadedFile] params, ?bool _first, ?bool multipart) -> bool
|
34
|
+
| (Hash[String, Hash[String, String] | Rack::Test::UploadedFile] params, ?bool _first, ?bool multipart) -> bool
|
35
|
+
| (Hash[String, Rack::Test::UploadedFile | String] params, ?bool _first, ?bool multipart) -> bool
|
36
|
+
| (Hash[String, Rack::Test::UploadedFile] params, ?bool _first, ?bool multipart) -> bool
|
37
|
+
| (Hash[String, Array[String] | Rack::Test::UploadedFile] params, ?bool _first, ?bool multipart) -> bool
|
38
|
+
| (Hash[String, Array[Hash[String, String]]] params, ?bool _first, ?bool multipart) -> nil
|
39
|
+
| (Hash[String, Array[Rack::Test::UploadedFile] | String] params, ?bool _first, ?bool multipart) -> bool
|
40
|
+
| (Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile]] | Array[String]] params, ?bool _first, ?bool multipart) -> bool
|
41
|
+
| (Hash[String, Array[Rack::Test::UploadedFile | String]] params, ?bool _first, ?bool multipart) -> bool
|
42
|
+
| (Hash[String, Hash[String, String] | String | Rack::Test::UploadedFile] params, ?bool _first, ?bool multipart) -> bool
|
43
|
+
| (Hash[String, untyped] params, ?bool _first, ?bool multipart) -> bool
|
44
|
+
| (Hash[String, Hash[String, Array[Hash[String, String] | Hash[String, Array[Hash[String, String]] | String]]] | Rack::Test::UploadedFile] params, ?bool _first, ?bool multipart) -> bool
|
45
|
+
| (Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile] | Hash[String, Array[String] | String]]] params, ?bool _first, ?bool multipart) -> bool
|
46
|
+
| (Hash[String, Array[Hash[String, String]] | Rack::Test::UploadedFile] params, ?bool _first, ?bool multipart) -> bool
|
47
|
+
| (Hash[String, String | Rack::Test::UploadedFile] params, ?bool _first, ?bool multipart) -> bool
|
48
|
+
| (Hash[String, Array[Hash[String, Rack::Test::UploadedFile | String]] | Array[String]] params, ?bool _first, ?bool multipart) -> bool
|
49
|
+
| (Hash[String, Array[Hash[String, Array[String] | String]]] params, ?bool _first, ?bool multipart) -> String
|
50
|
+
|
51
|
+
private def normalize_multipart_params: (Hash[String, Array[Rack::Test::UploadedFile]] params, ?bool first) -> Hash[String, Array[Rack::Test::UploadedFile]]
|
52
|
+
| (Hash[String, String] params, ?bool first) -> Hash[String, String]
|
53
|
+
| (Hash[String, Hash[String, String]] params, ?bool first) -> Hash[String, String]
|
54
|
+
| (Hash[String, Hash[String, Hash[String, String]] | Rack::Test::UploadedFile] params, ?bool first) -> Hash[String, Rack::Test::UploadedFile | String]
|
55
|
+
| (Hash[String, Hash[String, String] | Rack::Test::UploadedFile] params, ?bool first) -> Hash[String, Rack::Test::UploadedFile | String]
|
56
|
+
| (Hash[String, Rack::Test::UploadedFile | String] params, ?bool first) -> Hash[String, Rack::Test::UploadedFile | String]
|
57
|
+
| (Hash[String, Rack::Test::UploadedFile] params, ?bool first) -> Hash[String, Rack::Test::UploadedFile]
|
58
|
+
| (Hash[String, Array[String] | Rack::Test::UploadedFile] params, ?bool first) -> Hash[String, Array[String] | Rack::Test::UploadedFile]
|
59
|
+
| (Hash[String, Array[Rack::Test::UploadedFile] | String] params, ?bool first) -> Hash[String, Array[Rack::Test::UploadedFile] | String]
|
60
|
+
| (Hash[String, String | Rack::Test::UploadedFile] params, ?bool first) -> Hash[String, String | Rack::Test::UploadedFile]
|
61
|
+
| (Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile]] | Array[String]] params, ?bool first) -> Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile]] | Array[String]]
|
62
|
+
| (Hash[String, Array[Rack::Test::UploadedFile | String]] params, ?bool first) -> Hash[String, Array[Rack::Test::UploadedFile | String]]
|
63
|
+
| (Hash[String, Hash[String, String] | String | Rack::Test::UploadedFile] params, ?bool first) -> Hash[String, String | Rack::Test::UploadedFile]
|
64
|
+
| (Hash[String, untyped] params, ?bool first) -> Hash[String, untyped]
|
65
|
+
| (Hash[String, Array[Hash[String, String]] | String] params, ?bool first) -> Hash[String, Array[Hash[String, String]] | String]
|
66
|
+
| (Hash[String, Array[Hash[String, String] | Hash[String, Array[Hash[String, String]] | String]]] params, ?bool first) -> Hash[String, Array[Hash[String, String] | Hash[String, Array[Hash[String, String]] | String]]]
|
67
|
+
| (Hash[String, Hash[String, Array[Hash[String, String] | Hash[String, Array[Hash[String, String]] | String]]] | Rack::Test::UploadedFile] params, ?bool first) -> Hash[String, Array[Hash[String, String] | Hash[String, Array[Hash[String, String]] | String]] | Rack::Test::UploadedFile]
|
68
|
+
| (Hash[String, Array[String] | String] params, ?bool first) -> Hash[String, Array[String] | String]
|
69
|
+
| (Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile] | Hash[String, Array[String] | String]]] params, ?bool first) -> Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile] | Hash[String, Array[String] | String]]]
|
70
|
+
| (Hash[String, Array[Hash[String, String]] | Rack::Test::UploadedFile] params, ?bool first) -> Hash[String, Array[Hash[String, String]] | Rack::Test::UploadedFile]
|
71
|
+
| (Hash[String, Array[Hash[String, Rack::Test::UploadedFile | String]] | Array[String]] params, ?bool first) -> Hash[String, Array[Hash[String, Rack::Test::UploadedFile | String]] | Array[String]]
|
72
|
+
| (Hash[String, Array[Hash[String, Array[String] | String]]] params, ?bool first) -> Hash[String, Array[Hash[String, Array[String] | String]]]
|
73
|
+
|
74
|
+
private def _build_parts: (String buffer, Hash[String, Array[Rack::Test::UploadedFile]] parameters) -> File
|
75
|
+
| (String buffer, Hash[String, String] parameters) -> Array[Array[String]]
|
76
|
+
| (String buffer, Hash[String, Rack::Test::UploadedFile | String] parameters) -> File
|
77
|
+
| (String buffer, Hash[String, Rack::Test::UploadedFile] parameters) -> File
|
78
|
+
| (String buffer, Hash[String, Array[String] | Rack::Test::UploadedFile] parameters) -> File
|
79
|
+
| (String buffer, Hash[String, Array[Rack::Test::UploadedFile] | String] parameters) -> File
|
80
|
+
| (String buffer, Hash[String, String | Rack::Test::UploadedFile] parameters) -> File
|
81
|
+
| (String buffer, Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile]] | Array[String]] parameters) -> singleton(Object)
|
82
|
+
| (String buffer, Hash[String, Array[Rack::Test::UploadedFile | String]] parameters) -> File
|
83
|
+
| (String buffer, Hash[String, untyped] parameters) -> bool
|
84
|
+
| (String buffer, Hash[String, Array[Hash[String, String] | Hash[String, Array[Hash[String, String]] | String]] | Rack::Test::UploadedFile] parameters) -> File
|
85
|
+
| (String buffer, Hash[String, Array[Hash[String, String]] | String] parameters) -> Array[Array[String] | Array[Hash[String, String]]]
|
86
|
+
| (String buffer, Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile] | Hash[String, Array[String] | String]]] parameters) -> singleton(Object)
|
87
|
+
| (String buffer, Hash[String, Array[String] | String] parameters) -> Array[Array[String]]
|
88
|
+
| (String buffer, Hash[String, Array[Hash[String, String]] | Rack::Test::UploadedFile] parameters) -> File
|
89
|
+
| (String buffer, Hash[String, Array[Hash[String, Rack::Test::UploadedFile | String]] | Array[String]] parameters) -> singleton(Object)
|
90
|
+
| (String buffer, Hash[String, Array[Hash[String, Array[String] | String]]] parameters) -> Array[Array[Hash[String, Array[String] | String]]]
|
91
|
+
|
92
|
+
private def build_parts: (String buffer, Hash[String, Array[Rack::Test::UploadedFile]] parameters) -> singleton(Object)
|
93
|
+
| (String buffer, Hash[String, String] parameters) -> String
|
94
|
+
| (String buffer, Hash[String, Rack::Test::UploadedFile | String] parameters) -> singleton(Object)
|
95
|
+
| (String buffer, Hash[String, Rack::Test::UploadedFile] parameters) -> singleton(Object)
|
96
|
+
| (String buffer, Hash[String, Array[String] | Rack::Test::UploadedFile] parameters) -> singleton(Object)
|
97
|
+
| (String buffer, Hash[String, Array[Rack::Test::UploadedFile] | String] parameters) -> singleton(Object)
|
98
|
+
| (String buffer, Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile]] | Array[String]] parameters) -> bool
|
99
|
+
| (String buffer, Hash[String, Array[Rack::Test::UploadedFile | String]] parameters) -> singleton(Object)
|
100
|
+
| (String buffer, Hash[String, String | Rack::Test::UploadedFile] parameters) -> singleton(Object)
|
101
|
+
| (String buffer, Hash[String, untyped] parameters) -> bool
|
102
|
+
| (String buffer, Hash[String, Array[Hash[String, String] | Hash[String, Array[Hash[String, String]] | String]] | Rack::Test::UploadedFile] parameters) -> singleton(Object)
|
103
|
+
| (String buffer, Hash[String, Array[Hash[String, String | Rack::Test::UploadedFile] | Hash[String, Array[String] | String]]] parameters) -> bool
|
104
|
+
| (String buffer, Hash[String, Array[Hash[String, String]] | Rack::Test::UploadedFile] parameters) -> singleton(Object)
|
105
|
+
| (String buffer, Hash[String, Array[Hash[String, Rack::Test::UploadedFile | String]] | Array[String]] parameters) -> bool
|
106
|
+
| (String buffer, Hash[String, Array[Hash[String, Array[String] | String]]] parameters) -> String
|
107
|
+
|
108
|
+
private def build_file_part: (String buffer, String parameter_name, Rack::Test::UploadedFile uploaded_file) -> String
|
109
|
+
| (String buffer, String parameter_name, untyped uploaded_file) -> String
|
110
|
+
|
111
|
+
private def build_primitive_part: (String buffer, String parameter_name, String value) -> String
|
112
|
+
end
|
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
module Orthoses
|
4
4
|
class CallTracer
|
5
|
+
# CallTracer::Lazy is possible to perform a trace
|
6
|
+
# equivalent to CallTracer before method is defined.
|
7
|
+
# scope = CallTracerLazy.new
|
8
|
+
# scope.trace("ActiveRecord::Base#scope") do
|
9
|
+
# require 'active_record/all'
|
10
|
+
# @loader.call
|
11
|
+
# end
|
12
|
+
# scope.captures.each do |capture|
|
13
|
+
# capture.argument[:name]
|
14
|
+
# capture.argument[:body]
|
15
|
+
# capture.argument[:block]
|
16
|
+
# end
|
5
17
|
class Lazy
|
6
18
|
include Capturable
|
7
19
|
|
@@ -9,32 +9,55 @@ module Orthoses
|
|
9
9
|
|
10
10
|
def update_decl
|
11
11
|
return unless @decl.respond_to?(:members)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# avoid to duplicate and keep order
|
16
|
-
uniq_map[Object.new] = member
|
17
|
-
else
|
18
|
-
key = member_key(member)
|
19
|
-
drop_member = uniq_map[key]
|
20
|
-
uniq_map[key] = member
|
21
|
-
if drop_member
|
22
|
-
Orthoses.logger.info("#{@decl.name} \"#{member.location.source}\" was droped since duplication")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
12
|
+
|
13
|
+
uniq_map = uniq_members
|
14
|
+
drop_set_method_definition(uniq_map)
|
26
15
|
drop_known_method_definition(uniq_map)
|
16
|
+
|
27
17
|
@decl.members.replace(uniq_map.values)
|
28
18
|
end
|
29
19
|
|
30
20
|
private
|
31
21
|
|
22
|
+
def uniq_members
|
23
|
+
{}.tap do |uniq_map|
|
24
|
+
@decl.members.each do |member|
|
25
|
+
if member.instance_of?(RBS::AST::Members::MethodDefinition) && member.overloading?
|
26
|
+
# avoid to duplicate and keep order
|
27
|
+
uniq_map[Object.new] = member
|
28
|
+
else
|
29
|
+
key = member_key(member)
|
30
|
+
drop_member = uniq_map[key]
|
31
|
+
uniq_map[key] = member
|
32
|
+
if drop_member
|
33
|
+
Orthoses.logger.info("#{@decl.name} \"#{member.location.source}\" was droped since duplication")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def drop_set_method_definition(uniq_map)
|
41
|
+
attr_accessors = uniq_map.values.grep(RBS::AST::Members::AttrAccessor)
|
42
|
+
attr_accessors.each do |member|
|
43
|
+
uniq_map.delete([RBS::AST::Members::MethodDefinition, :"#{member.name}=", member.kind])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
32
47
|
def drop_known_method_definition(uniq_map)
|
33
48
|
decl_name = @decl.name.absolute!
|
34
49
|
if m_entry = @env.class_decls[decl_name]
|
35
50
|
m_entry.decls.each do |d|
|
36
|
-
d.decl.members.
|
37
|
-
|
51
|
+
d.decl.members.each do |member|
|
52
|
+
case member
|
53
|
+
when RBS::AST::Members::LocationOnly
|
54
|
+
# ignore
|
55
|
+
when RBS::AST::Members::AttrAccessor
|
56
|
+
uniq_map.delete([RBS::AST::Members::MethodDefinition, member.name, member.kind])
|
57
|
+
uniq_map.delete([RBS::AST::Members::MethodDefinition, :"#{member.name}=", member.kind])
|
58
|
+
else
|
59
|
+
uniq_map.delete(member_key(member))
|
60
|
+
end
|
38
61
|
end
|
39
62
|
end
|
40
63
|
end
|
@@ -60,12 +83,11 @@ module Orthoses
|
|
60
83
|
when RBS::AST::Members::Alias
|
61
84
|
[RBS::AST::Members::MethodDefinition, member.new_name, member.kind]
|
62
85
|
when RBS::AST::Members::AttrAccessor
|
63
|
-
# FIXME: how to check "#{member.name}=" ?
|
64
86
|
[RBS::AST::Members::MethodDefinition, member.name, member.kind]
|
65
87
|
when RBS::AST::Members::AttrReader
|
66
88
|
[RBS::AST::Members::MethodDefinition, member.name, member.kind]
|
67
89
|
when RBS::AST::Members::AttrWriter
|
68
|
-
[RBS::AST::Members::MethodDefinition, "#{member.name}=", member.kind]
|
90
|
+
[RBS::AST::Members::MethodDefinition, :"#{member.name}=", member.kind]
|
69
91
|
else
|
70
92
|
[member.class, member.name]
|
71
93
|
end
|
@@ -7,7 +7,8 @@ module Orthoses
|
|
7
7
|
paths.each do |path|
|
8
8
|
Orthoses.logger.debug("Load #{path}")
|
9
9
|
buffer = RBS::Buffer.new(name: path.to_s, content: File.read(path.to_s, encoding: "UTF-8"))
|
10
|
-
RBS::Parser.parse_signature(buffer)
|
10
|
+
_, _, decls = RBS::Parser.parse_signature(buffer)
|
11
|
+
decls.each do |decl|
|
11
12
|
env << decl
|
12
13
|
end
|
13
14
|
end
|
@@ -15,9 +16,17 @@ module Orthoses
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
def initialize(
|
19
|
+
def initialize(
|
20
|
+
method_definition_filter: nil,
|
21
|
+
alias_filter: nil,
|
22
|
+
constant_filter: nil,
|
23
|
+
mixin_filter: nil,
|
24
|
+
attribute_filter: nil
|
25
|
+
)
|
19
26
|
@load_env = RBS::Environment.new
|
20
27
|
@known_env = Utils.rbs_environment(cache: false)
|
28
|
+
@method_definition_filter = method_definition_filter
|
29
|
+
@alias_filter = alias_filter
|
21
30
|
@constant_filter = constant_filter
|
22
31
|
@mixin_filter = mixin_filter
|
23
32
|
@attribute_filter = attribute_filter
|
@@ -33,7 +42,8 @@ module Orthoses
|
|
33
42
|
def write_to(store:)
|
34
43
|
each do |add_content|
|
35
44
|
content = store[add_content.name]
|
36
|
-
content.header
|
45
|
+
content.header ||= add_content.header
|
46
|
+
content.comment ||= add_content.comment
|
37
47
|
content.concat(add_content.body)
|
38
48
|
end
|
39
49
|
end
|
@@ -46,6 +56,7 @@ module Orthoses
|
|
46
56
|
@load_env.class_decls.each do |type_name, m_entry|
|
47
57
|
name = type_name.relative!.to_s
|
48
58
|
content = Content.new(name: name)
|
59
|
+
content.comment = m_entry.primary.decl.comment&.string&.gsub(/^/, "# ")
|
49
60
|
content.header = header_builder.build(entry: m_entry, name_hint: name)
|
50
61
|
decls_to_lines(m_entry.decls.map(&:decl)).each do |line|
|
51
62
|
content << line
|
@@ -93,9 +104,12 @@ module Orthoses
|
|
93
104
|
when RBS::AST::Declarations::Constant
|
94
105
|
next unless @constant_filter.nil? || @constant_filter.call(member)
|
95
106
|
when RBS::AST::Members::MethodDefinition
|
107
|
+
next unless @method_definition_filter.nil? || @method_definition_filter.call(member)
|
96
108
|
if last_visibility == :private && member.kind != :singleton_instance
|
97
109
|
member.instance_variable_set(:@visibility, :private)
|
98
110
|
end
|
111
|
+
when RBS::AST::Members::Alias
|
112
|
+
next unless @alias_filter.nil? || @alias_filter.call(member)
|
99
113
|
when RBS::AST::Members::Mixin
|
100
114
|
next unless @mixin_filter.nil? || @mixin_filter.call(member)
|
101
115
|
when RBS::AST::Members::Attribute
|
@@ -3,7 +3,7 @@ module Orthoses
|
|
3
3
|
class HeaderBuilder
|
4
4
|
def initialize(env:)
|
5
5
|
@env = env
|
6
|
-
@resolver = RBS::TypeNameResolver.
|
6
|
+
@resolver = RBS::Resolver::TypeNameResolver.new(env)
|
7
7
|
end
|
8
8
|
|
9
9
|
def build(entry:, name_hint: nil)
|
@@ -66,11 +66,10 @@ module Orthoses
|
|
66
66
|
"interface #{name_and_params(resolved_name.relative!, entry.decl.type_params)}"
|
67
67
|
end
|
68
68
|
|
69
|
+
include RBS::Environment::ContextUtil
|
70
|
+
|
69
71
|
def build_context(entry:)
|
70
|
-
|
71
|
-
entry.outer[0, i + 1].map(&:name).inject(:+).to_namespace.absolute!
|
72
|
-
end
|
73
|
-
context.push(RBS::Namespace.root)
|
72
|
+
calculate_context(entry.outer + [entry.decl])
|
74
73
|
end
|
75
74
|
|
76
75
|
def name_and_params(name, params)
|
data/lib/orthoses/content.rb
CHANGED
@@ -74,12 +74,52 @@ module Orthoses
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def original_rbs
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
io = StringIO.new
|
78
|
+
io.puts @comment if @comment
|
79
|
+
io.puts @header
|
80
|
+
@body.each do |line|
|
81
|
+
io.puts " #{line}"
|
82
|
+
end
|
83
|
+
io.puts "end"
|
84
|
+
io.string
|
85
|
+
end
|
86
|
+
|
87
|
+
def auto_header
|
88
|
+
env = Utils.rbs_environment
|
89
|
+
if entry = env.class_decls[TypeName(name).absolute!]
|
90
|
+
@header = Content::HeaderBuilder.new(env: env).build(entry: entry)
|
91
|
+
return
|
92
|
+
end
|
93
|
+
|
94
|
+
return unless @header.nil?
|
95
|
+
|
96
|
+
if interface?
|
97
|
+
self.header = "interface #{name}"
|
98
|
+
return
|
99
|
+
end
|
100
|
+
|
101
|
+
val = Object.const_get(name)
|
102
|
+
|
103
|
+
case val
|
104
|
+
when Class
|
105
|
+
superclass =
|
106
|
+
if val.superclass && val.superclass != Object
|
107
|
+
super_module_name = Utils.module_name(val.superclass)
|
108
|
+
|
109
|
+
if super_module_name && super_module_name != "Random::Base" # https://github.com/ruby/rbs/pull/977
|
110
|
+
" < ::#{super_module_name}#{temporary_type_params(super_module_name)}"
|
111
|
+
else
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
else
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
self.header = "class #{Utils.module_name(val)}#{type_params(name)}#{superclass}"
|
118
|
+
when Module
|
119
|
+
self.header = "module #{Utils.module_name(val)}#{type_params(name)}"
|
120
|
+
else
|
121
|
+
raise "#{val.inspect} is not class/module"
|
122
|
+
end
|
83
123
|
end
|
84
124
|
|
85
125
|
private
|
@@ -119,7 +159,7 @@ module Orthoses
|
|
119
159
|
name: "orthoses/content.rb",
|
120
160
|
content: original_rbs
|
121
161
|
)
|
122
|
-
parsed_decls = RBS::Parser.parse_signature(buffer)
|
162
|
+
_, _, parsed_decls = RBS::Parser.parse_signature(buffer)
|
123
163
|
unless parsed_decls.length == 1
|
124
164
|
raise "expect decls.length == 1, but got #{parsed_decls.length}"
|
125
165
|
end
|
@@ -132,44 +172,6 @@ module Orthoses
|
|
132
172
|
raise
|
133
173
|
end
|
134
174
|
|
135
|
-
def auto_header
|
136
|
-
env = Utils.rbs_environment
|
137
|
-
if entry = env.class_decls[TypeName(name).absolute!]
|
138
|
-
@header = Content::HeaderBuilder.new(env: env).build(entry: entry)
|
139
|
-
return
|
140
|
-
end
|
141
|
-
|
142
|
-
return unless @header.nil?
|
143
|
-
|
144
|
-
if interface?
|
145
|
-
self.header = "interface #{name}"
|
146
|
-
return
|
147
|
-
end
|
148
|
-
|
149
|
-
val = Object.const_get(name)
|
150
|
-
|
151
|
-
case val
|
152
|
-
when Class
|
153
|
-
superclass =
|
154
|
-
if val.superclass && val.superclass != Object
|
155
|
-
super_module_name = Utils.module_name(val.superclass)
|
156
|
-
|
157
|
-
if super_module_name && super_module_name != "Random::Base" # https://github.com/ruby/rbs/pull/977
|
158
|
-
" < ::#{super_module_name}#{temporary_type_params(super_module_name)}"
|
159
|
-
else
|
160
|
-
nil
|
161
|
-
end
|
162
|
-
else
|
163
|
-
nil
|
164
|
-
end
|
165
|
-
self.header = "class #{Utils.module_name(val)}#{type_params(name)}#{superclass}"
|
166
|
-
when Module
|
167
|
-
self.header = "module #{Utils.module_name(val)}#{type_params(name)}"
|
168
|
-
else
|
169
|
-
raise "#{val.inspect} is not class/module"
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
175
|
def temporary_type_params(name)
|
174
176
|
Utils.known_type_params(name)&.then do |params|
|
175
177
|
if params.empty?
|
data/lib/orthoses/filter.rb
CHANGED
@@ -16,8 +16,8 @@ module Orthoses
|
|
16
16
|
def call
|
17
17
|
@loader.call.tap do |store|
|
18
18
|
store.filter! do |name, content|
|
19
|
-
@block.call(name, content).tap do
|
20
|
-
Orthoses.logger.debug("Filter
|
19
|
+
@block.call(name, content).tap do |bool|
|
20
|
+
Orthoses.logger.debug("[Filter] #{bool ? "Pass" : "Reject"} [#{name}]")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -1,11 +1,23 @@
|
|
1
1
|
module Orthoses
|
2
2
|
# Call `rbs prototype rb` and add to store
|
3
3
|
# use Orthoses::RBSPrototypeRB,
|
4
|
-
# paths: Dir.glob("lib/**/*.rb")
|
4
|
+
# paths: Dir.glob("lib/**/*.rb"),
|
5
|
+
# method_definition_filter: ->(member) { false },
|
6
|
+
# alias_filter: ->(member) { false }
|
5
7
|
class RBSPrototypeRB
|
6
|
-
def initialize(
|
8
|
+
def initialize(
|
9
|
+
loader,
|
10
|
+
paths:,
|
11
|
+
method_definition_filter: nil,
|
12
|
+
alias_filter: nil,
|
13
|
+
constant_filter: nil,
|
14
|
+
mixin_filter: nil,
|
15
|
+
attribute_filter: nil
|
16
|
+
)
|
7
17
|
@loader = loader
|
8
18
|
@paths = paths
|
19
|
+
@method_definition_filter = method_definition_filter
|
20
|
+
@alias_filter = alias_filter
|
9
21
|
@constant_filter = constant_filter
|
10
22
|
@mixin_filter = mixin_filter
|
11
23
|
@attribute_filter = attribute_filter
|
@@ -23,6 +35,8 @@ module Orthoses
|
|
23
35
|
end
|
24
36
|
end
|
25
37
|
env = Orthoses::Content::Environment.new(
|
38
|
+
method_definition_filter: @method_definition_filter,
|
39
|
+
alias_filter: @alias_filter,
|
26
40
|
constant_filter: @constant_filter,
|
27
41
|
mixin_filter: @mixin_filter,
|
28
42
|
attribute_filter: @attribute_filter,
|
@@ -169,8 +169,13 @@ module Orthoses
|
|
169
169
|
kind: kind,
|
170
170
|
location: nil,
|
171
171
|
name: method_id,
|
172
|
-
|
173
|
-
|
172
|
+
overloading: false,
|
173
|
+
overloads: types.map { |type|
|
174
|
+
RBS::AST::Members::MethodDefinition::Overload.new(
|
175
|
+
annotations: [],
|
176
|
+
method_type: type
|
177
|
+
)
|
178
|
+
},
|
174
179
|
visibility: visibility
|
175
180
|
)
|
176
181
|
]
|
data/lib/orthoses/utils.rb
CHANGED
@@ -50,28 +50,6 @@ module Orthoses
|
|
50
50
|
RBS::Namespace.parse(name).to_type_name
|
51
51
|
end
|
52
52
|
|
53
|
-
class << self
|
54
|
-
# Generated scripts are not always located in the root.
|
55
|
-
# By default, it follows the upper level directory from the current directory
|
56
|
-
# to find the rbs_collection.yaml file and set it to `rbs_collection_pathname`.
|
57
|
-
# It can be reconfigured if necessary.
|
58
|
-
attr_accessor :rbs_collection_pathname
|
59
|
-
end
|
60
|
-
# set default
|
61
|
-
self.rbs_collection_pathname = ->() {
|
62
|
-
begin
|
63
|
-
start = here = Dir.pwd
|
64
|
-
until ok = RBS::Collection::Config::PATH.exist?
|
65
|
-
Dir.chdir("..")
|
66
|
-
return nil if Dir.pwd == here
|
67
|
-
here = Dir.pwd
|
68
|
-
end
|
69
|
-
Pathname(here) + RBS::Collection::Config::PATH
|
70
|
-
ensure
|
71
|
-
Dir.chdir(start)
|
72
|
-
end
|
73
|
-
}.call
|
74
|
-
|
75
53
|
def self.rbs_environment(library: nil, collection: true, cache: true)
|
76
54
|
@env_cache ||= {}
|
77
55
|
if cache && hit = @env_cache[[library, collection]]
|
@@ -80,9 +58,15 @@ module Orthoses
|
|
80
58
|
|
81
59
|
loader = RBS::EnvironmentLoader.new
|
82
60
|
|
83
|
-
if collection
|
84
|
-
|
85
|
-
|
61
|
+
if collection
|
62
|
+
config_path = RBS::Collection::Config.find_config_path || RBS::Collection::Config::PATH || raise("needs rbs_collection.yaml")
|
63
|
+
lock_path = RBS::Collection::Config.to_lockfile_path(config_path)
|
64
|
+
raise "needs rbs_collection.yaml file" unless lock_path.file?
|
65
|
+
lock = RBS::Collection::Config::Lockfile.from_lockfile(
|
66
|
+
lockfile_path: lock_path,
|
67
|
+
data: YAML.load_file(lock_path.to_s)
|
68
|
+
)
|
69
|
+
loader.add_collection(lock)
|
86
70
|
end
|
87
71
|
|
88
72
|
case library
|
data/lib/orthoses/version.rb
CHANGED
data/orthoses.gemspec
CHANGED
data/sig/orthoses/builder.rbs
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
|
+
# Middleware builder like the Rack
|
4
|
+
# Builder.new do
|
5
|
+
# use Orthoses::CreateFileByName
|
6
|
+
# use Orthoses::Constant
|
7
|
+
# use Orthoses::Mixin
|
8
|
+
# use Orthoses::Walk,
|
9
|
+
# root: "Foo"
|
10
|
+
# run ->() { require 'foo' }
|
11
|
+
# end
|
3
12
|
class Orthoses::Builder
|
4
13
|
def initialize: () ?{ () -> untyped } -> void
|
5
14
|
def use: (untyped middleware, *untyped args, **untyped key) ?{ () -> untyped } -> untyped
|
@@ -1,6 +1,19 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
|
+
# CallTracer::Lazy is possible to perform a trace
|
4
|
+
# equivalent to CallTracer before method is defined.
|
5
|
+
# scope = CallTracerLazy.new
|
6
|
+
# scope.trace("ActiveRecord::Base#scope") do
|
7
|
+
# require 'active_record/all'
|
8
|
+
# @loader.call
|
9
|
+
# end
|
10
|
+
# scope.captures.each do |capture|
|
11
|
+
# capture.argument[:name]
|
12
|
+
# capture.argument[:body]
|
13
|
+
# capture.argument[:block]
|
14
|
+
# end
|
3
15
|
class Orthoses::CallTracer::Lazy
|
4
16
|
def initialize: () -> void
|
5
|
-
def trace: (
|
17
|
+
def trace: (String name) ?{ () -> untyped } -> untyped
|
18
|
+
attr_reader captures: Array[untyped]
|
6
19
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
|
+
# Check and drop duplication method, const etc...
|
3
4
|
class Orthoses::Content::DuplicationChecker
|
4
5
|
def initialize: (untyped decl, ?env: untyped?) -> void
|
5
6
|
def update_decl: () -> (nil | untyped)
|
7
|
+
private def uniq_members: () -> untyped
|
8
|
+
private def drop_set_method_definition: (untyped uniq_map) -> untyped
|
6
9
|
private def drop_known_method_definition: (untyped uniq_map) -> untyped
|
7
10
|
private def member_key: (untyped member) -> untyped
|
8
11
|
end
|
@@ -10,4 +10,5 @@ class Orthoses::Content::HeaderBuilder
|
|
10
10
|
private def build_context: (entry: untyped) -> untyped
|
11
11
|
private def name_and_params: (untyped name, untyped params) -> ::String
|
12
12
|
private def name_and_args: (untyped name, untyped args) -> (::String | nil)
|
13
|
+
include RBS::Environment::ContextUtil
|
13
14
|
end
|
data/sig/orthoses/content.rbs
CHANGED
@@ -12,10 +12,10 @@ class Orthoses::Content
|
|
12
12
|
def uniq!: () -> untyped
|
13
13
|
def sort!: () -> untyped
|
14
14
|
def original_rbs: () -> untyped
|
15
|
+
def auto_header: () -> (nil | untyped)
|
15
16
|
private def decl_to_lines: (untyped decl) -> untyped
|
16
17
|
private def uniqed_body_string: () -> String
|
17
18
|
private def uniqed_body_decl: () -> RBS::AST::Declarations::t
|
18
|
-
private def auto_header: () -> (nil | untyped)
|
19
19
|
private def temporary_type_params: (untyped name) -> untyped
|
20
20
|
private def type_params: (untyped name) -> untyped
|
21
21
|
attr_reader name: String
|
data/sig/orthoses/filter.rbs
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# THIS IS GENERATED CODE from `$ rake generate_self_sig`
|
2
2
|
|
3
|
+
# Filter current store.
|
4
|
+
# filter stored key and value if proc return true
|
5
|
+
# use Orthoses::Filter do |name, content|
|
6
|
+
# Orthoses.rbs_defined_class?(name)
|
7
|
+
# end
|
3
8
|
class Orthoses::Filter
|
4
9
|
def initialize: (Orthoses::_Call loader) { (String, Orthoses::Content) -> boolish } -> void
|
5
10
|
def call: () -> Orthoses::store
|