15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/orthoses/delegate_class.rb', line 15
def call
require 'delegate'
::Class.prepend(Hook)
inherited = CallTracer.new
delegate_class_super_map = {}
delegate_class_tracer = TracePoint.new(:return) do |tp|
return_value = tp.return_value
superclass = tp.binding.local_variable_get(:superclass)
delegate_class_super_map[return_value] = superclass
end
store = delegate_class_tracer.enable(target: method(:DelegateClass)) do
inherited.trace(Hook.instance_method(:inherited)) do
@loader.call
end
end
store["Class"].body.delete("prepend Orthoses::DelegateClass::Hook")
inherited.captures.each do |capture|
superclass = capture.method.receiver
if delegate_to_class = delegate_class_super_map[superclass]
subclass = capture.argument[:subclass]
subclass_name = Utils.module_name(subclass)
next unless subclass_name
delegate_to_class_name = Utils.module_name(delegate_to_class)
next unless delegate_to_class_name
= "class #{subclass_name} < ::#{delegate_to_class_name}#{temporary_type_params(delegate_to_class_name)}"
store[subclass_name]. =
end
end
store
end
|