orthoses 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/orthoses/attribute.rb +20 -18
- data/lib/orthoses/call_tracer.rb +14 -7
- data/lib/orthoses/content/environment.rb +14 -0
- data/lib/orthoses/delegate_class.rb +22 -8
- data/lib/orthoses/mixin.rb +40 -18
- data/lib/orthoses/version.rb +1 -1
- data/sig/orthoses/attribute.rbs +1 -2
- 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 +6 -7
- data/sig/orthoses/content.rbs +6 -8
- data/sig/orthoses/delegate_class/hook.rbs +5 -0
- data/sig/orthoses/mixin/hook.rbs +9 -0
- data/sig/orthoses/mixin.rbs +4 -2
- data/sig/orthoses/utils.rbs +1 -1
- data/sig/orthoses.rbs +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2941ebbe45d7ab2dc9ad009628db52419a6a3b18a1fd1ad870164ab017bbb5e1
|
4
|
+
data.tar.gz: 5a33b4b63f62b820f4642d56661cebd393c3381363a8f727655f123568b2784b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd9a27c8a8f6752fc73c2c65b8dbb0edcb9885425667a8a067a6d56cc2bb32473db565ea41089ad0f8b26c598275afa83e2fb3bbde6f668fc095c942bb75af01
|
7
|
+
data.tar.gz: 4b6c157a129e1e3dfab42737ba1a4ba0f9c1c5ffe25defb693de3bce39f63fdcc746b155d030e273162e550ada315281553d921475bd4a333bf362a46e5a58bd
|
data/Gemfile.lock
CHANGED
data/lib/orthoses/attribute.rb
CHANGED
@@ -23,17 +23,17 @@ 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
|
@@ -42,22 +42,23 @@ module Orthoses
|
|
42
42
|
|
43
43
|
store["Module"].body.delete("prepend Orthoses::Attribute::Hook")
|
44
44
|
|
45
|
-
attr.
|
46
|
-
m = method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
45
|
+
attr.captures.each do |capture|
|
46
|
+
m = capture.method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
47
47
|
if m && m[1]
|
48
48
|
receiver_name = m[1]
|
49
49
|
prefix = "self."
|
50
50
|
else
|
51
|
-
receiver_name = Utils.module_name(method.receiver) or next
|
51
|
+
receiver_name = Utils.module_name(capture.method.receiver) or next
|
52
52
|
prefix = nil
|
53
53
|
end
|
54
54
|
content = store[receiver_name]
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
names = capture.argument[:names]
|
56
|
+
if names[1].equal?(true)
|
57
|
+
content << "attr_accessor #{prefix}#{names[0]}: untyped"
|
58
|
+
elsif names[1].equal?(false)
|
59
|
+
content << "attr_reader #{prefix}#{names[0]}: untyped"
|
59
60
|
else
|
60
|
-
|
61
|
+
names.each do |name|
|
61
62
|
content << "attr_reader #{prefix}#{name}: untyped"
|
62
63
|
end
|
63
64
|
end
|
@@ -79,16 +80,17 @@ module Orthoses
|
|
79
80
|
private
|
80
81
|
|
81
82
|
def each_definition(call_tracer)
|
82
|
-
call_tracer.
|
83
|
-
m = method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
83
|
+
call_tracer.captures.each do |capture|
|
84
|
+
m = capture.method.receiver.to_s.match(/#<Class:([\w:]+)>/)
|
85
|
+
names = capture.argument[:names]
|
84
86
|
if m && m[1]
|
85
87
|
receiver_name = m[1]
|
86
|
-
|
88
|
+
names.each do |name|
|
87
89
|
yield [receiver_name, "self.#{name}"]
|
88
90
|
end
|
89
91
|
else
|
90
|
-
receiver_name = Utils.module_name(method.receiver) or next
|
91
|
-
|
92
|
+
receiver_name = Utils.module_name(capture.method.receiver) or next
|
93
|
+
names.each do |name|
|
92
94
|
yield [receiver_name, name]
|
93
95
|
end
|
94
96
|
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
|
@@ -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/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
|
+
store["Module"].body.delete("prepend Orthoses::Mixin::Hook")
|
38
|
+
|
39
|
+
collect_definitions(store, include, :include)
|
40
|
+
collect_definitions(store, extend, :extend)
|
41
|
+
collect_definitions(store, prepend, :prepend)
|
42
|
+
|
43
|
+
store
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
27
47
|
|
28
|
-
|
48
|
+
def collect_definitions(store, call_tracer, how)
|
49
|
+
call_tracer.captures.each do |capture|
|
50
|
+
base_mod = capture.method.receiver
|
29
51
|
next unless base_mod.kind_of?(Module)
|
52
|
+
|
30
53
|
base_mod_name = Utils.module_name(base_mod)
|
31
54
|
next unless base_mod_name
|
32
55
|
|
33
|
-
|
56
|
+
content = store[base_mod_name]
|
57
|
+
capture.argument[:modules].each do |mod|
|
34
58
|
mod_name = Utils.module_name(mod)
|
35
59
|
next unless mod_name
|
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
|
data/lib/orthoses/version.rb
CHANGED
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,10 @@
|
|
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
|
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 name_and_params: (untyped name, untyped params) -> ::String
|
11
|
+
private def name_and_args: (untyped name, untyped args) -> (::String | nil)
|
13
12
|
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/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
|
data/sig/orthoses/utils.rbs
CHANGED
@@ -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.8.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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- sig/orthoses/builder.rbs
|
74
74
|
- sig/orthoses/builder/call_logable.rbs
|
75
75
|
- sig/orthoses/call_tracer.rbs
|
76
|
+
- sig/orthoses/call_tracer/capture.rbs
|
76
77
|
- sig/orthoses/const_load_error.rbs
|
77
78
|
- sig/orthoses/constant.rbs
|
78
79
|
- sig/orthoses/content.rbs
|
@@ -81,9 +82,11 @@ files:
|
|
81
82
|
- sig/orthoses/content/header_builder.rbs
|
82
83
|
- sig/orthoses/create_file_by_name.rbs
|
83
84
|
- sig/orthoses/delegate_class.rbs
|
85
|
+
- sig/orthoses/delegate_class/hook.rbs
|
84
86
|
- sig/orthoses/filter.rbs
|
85
87
|
- sig/orthoses/load_rbs.rbs
|
86
88
|
- sig/orthoses/mixin.rbs
|
89
|
+
- sig/orthoses/mixin/hook.rbs
|
87
90
|
- sig/orthoses/name_space_error.rbs
|
88
91
|
- sig/orthoses/object_space_all.rbs
|
89
92
|
- sig/orthoses/pp.rbs
|