im 0.1.4 → 0.1.6
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/CHANGELOG.md +9 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +2 -144
- data/README.md +2 -2
- data/lib/im/kernel.rb +7 -33
- data/lib/im/module.rb +3 -2
- data/lib/im/version.rb +1 -1
- data/lib/im.rb +124 -55
- metadata +3 -5
- data/lib/im/autoload.rb +0 -10
- data/lib/im/constants.rb +0 -104
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ef66ecbb4745e878d911ec789567b204abe1bb174f57cee6b04ca6caddb76d9
|
|
4
|
+
data.tar.gz: a8cb56445189f2eb3d4fc4b7ff3b49c028b5b43cc7d8e20961481b125171d777
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4fed0705aca8dfd1eb036ea78c5e5a71f64837134669937a31c04daf97224744d6c881363a688adaf61fa01322c0b462c1d6fa57ac5bf53b2eee72deb633634
|
|
7
|
+
data.tar.gz: a3e0d1b7e940c0afd22d4415d855964b73a043390fd6538f075affe1eb29964c5b7c3b4cf675a738a6b999ab73cba72ce2ec86af790797866ff97ee685979fb5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.1.6] - 2022-10-03
|
|
4
|
+
- Remove `Object.const_missing` patch (Ruby patch now handles dynamic toplevel
|
|
5
|
+
references)
|
|
6
|
+
|
|
7
|
+
## [0.1.5] - 2022-09-22
|
|
8
|
+
- Rename Im::Dependency -> Im::Require
|
|
9
|
+
- Handle dynamic requires (require called from method body after file has been imported)
|
|
10
|
+
- Refactor: move require/autoload patch logic to Im handler methods
|
|
11
|
+
|
|
3
12
|
## [0.1.4] - 2022-09-19
|
|
4
13
|
- Correctly assign constants imported via recursive requires
|
|
5
14
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,144 +1,12 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
im (0.1.
|
|
4
|
+
im (0.1.6)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
actioncable (7.0.4)
|
|
10
|
-
actionpack (= 7.0.4)
|
|
11
|
-
activesupport (= 7.0.4)
|
|
12
|
-
nio4r (~> 2.0)
|
|
13
|
-
websocket-driver (>= 0.6.1)
|
|
14
|
-
actionmailbox (7.0.4)
|
|
15
|
-
actionpack (= 7.0.4)
|
|
16
|
-
activejob (= 7.0.4)
|
|
17
|
-
activerecord (= 7.0.4)
|
|
18
|
-
activestorage (= 7.0.4)
|
|
19
|
-
activesupport (= 7.0.4)
|
|
20
|
-
mail (>= 2.7.1)
|
|
21
|
-
net-imap
|
|
22
|
-
net-pop
|
|
23
|
-
net-smtp
|
|
24
|
-
actionmailer (7.0.4)
|
|
25
|
-
actionpack (= 7.0.4)
|
|
26
|
-
actionview (= 7.0.4)
|
|
27
|
-
activejob (= 7.0.4)
|
|
28
|
-
activesupport (= 7.0.4)
|
|
29
|
-
mail (~> 2.5, >= 2.5.4)
|
|
30
|
-
net-imap
|
|
31
|
-
net-pop
|
|
32
|
-
net-smtp
|
|
33
|
-
rails-dom-testing (~> 2.0)
|
|
34
|
-
actionpack (7.0.4)
|
|
35
|
-
actionview (= 7.0.4)
|
|
36
|
-
activesupport (= 7.0.4)
|
|
37
|
-
rack (~> 2.0, >= 2.2.0)
|
|
38
|
-
rack-test (>= 0.6.3)
|
|
39
|
-
rails-dom-testing (~> 2.0)
|
|
40
|
-
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
41
|
-
actiontext (7.0.4)
|
|
42
|
-
actionpack (= 7.0.4)
|
|
43
|
-
activerecord (= 7.0.4)
|
|
44
|
-
activestorage (= 7.0.4)
|
|
45
|
-
activesupport (= 7.0.4)
|
|
46
|
-
globalid (>= 0.6.0)
|
|
47
|
-
nokogiri (>= 1.8.5)
|
|
48
|
-
actionview (7.0.4)
|
|
49
|
-
activesupport (= 7.0.4)
|
|
50
|
-
builder (~> 3.1)
|
|
51
|
-
erubi (~> 1.4)
|
|
52
|
-
rails-dom-testing (~> 2.0)
|
|
53
|
-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
54
|
-
activejob (7.0.4)
|
|
55
|
-
activesupport (= 7.0.4)
|
|
56
|
-
globalid (>= 0.3.6)
|
|
57
|
-
activemodel (7.0.4)
|
|
58
|
-
activesupport (= 7.0.4)
|
|
59
|
-
activerecord (7.0.4)
|
|
60
|
-
activemodel (= 7.0.4)
|
|
61
|
-
activesupport (= 7.0.4)
|
|
62
|
-
activestorage (7.0.4)
|
|
63
|
-
actionpack (= 7.0.4)
|
|
64
|
-
activejob (= 7.0.4)
|
|
65
|
-
activerecord (= 7.0.4)
|
|
66
|
-
activesupport (= 7.0.4)
|
|
67
|
-
marcel (~> 1.0)
|
|
68
|
-
mini_mime (>= 1.1.0)
|
|
69
|
-
activesupport (7.0.4)
|
|
70
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
71
|
-
i18n (>= 1.6, < 2)
|
|
72
|
-
minitest (>= 5.1)
|
|
73
|
-
tzinfo (~> 2.0)
|
|
74
|
-
builder (3.2.4)
|
|
75
|
-
concurrent-ruby (1.1.10)
|
|
76
|
-
crass (1.0.6)
|
|
77
9
|
diff-lcs (1.5.0)
|
|
78
|
-
digest (3.1.0)
|
|
79
|
-
erubi (1.11.0)
|
|
80
|
-
globalid (1.0.0)
|
|
81
|
-
activesupport (>= 5.0)
|
|
82
|
-
i18n (1.12.0)
|
|
83
|
-
concurrent-ruby (~> 1.0)
|
|
84
|
-
loofah (2.19.0)
|
|
85
|
-
crass (~> 1.0.2)
|
|
86
|
-
nokogiri (>= 1.5.9)
|
|
87
|
-
mail (2.7.1)
|
|
88
|
-
mini_mime (>= 0.1.1)
|
|
89
|
-
marcel (1.0.2)
|
|
90
|
-
method_source (1.0.0)
|
|
91
|
-
mini_mime (1.1.2)
|
|
92
|
-
mini_portile2 (2.8.0)
|
|
93
|
-
minitest (5.16.3)
|
|
94
|
-
net-imap (0.2.3)
|
|
95
|
-
digest
|
|
96
|
-
net-protocol
|
|
97
|
-
strscan
|
|
98
|
-
net-pop (0.1.1)
|
|
99
|
-
digest
|
|
100
|
-
net-protocol
|
|
101
|
-
timeout
|
|
102
|
-
net-protocol (0.1.3)
|
|
103
|
-
timeout
|
|
104
|
-
net-smtp (0.3.1)
|
|
105
|
-
digest
|
|
106
|
-
net-protocol
|
|
107
|
-
timeout
|
|
108
|
-
nio4r (2.5.8)
|
|
109
|
-
nokogiri (1.13.8)
|
|
110
|
-
mini_portile2 (~> 2.8.0)
|
|
111
|
-
racc (~> 1.4)
|
|
112
|
-
racc (1.6.0)
|
|
113
|
-
rack (2.2.4)
|
|
114
|
-
rack-test (2.0.2)
|
|
115
|
-
rack (>= 1.3)
|
|
116
|
-
rails (7.0.4)
|
|
117
|
-
actioncable (= 7.0.4)
|
|
118
|
-
actionmailbox (= 7.0.4)
|
|
119
|
-
actionmailer (= 7.0.4)
|
|
120
|
-
actionpack (= 7.0.4)
|
|
121
|
-
actiontext (= 7.0.4)
|
|
122
|
-
actionview (= 7.0.4)
|
|
123
|
-
activejob (= 7.0.4)
|
|
124
|
-
activemodel (= 7.0.4)
|
|
125
|
-
activerecord (= 7.0.4)
|
|
126
|
-
activestorage (= 7.0.4)
|
|
127
|
-
activesupport (= 7.0.4)
|
|
128
|
-
bundler (>= 1.15.0)
|
|
129
|
-
railties (= 7.0.4)
|
|
130
|
-
rails-dom-testing (2.0.3)
|
|
131
|
-
activesupport (>= 4.2.0)
|
|
132
|
-
nokogiri (>= 1.6)
|
|
133
|
-
rails-html-sanitizer (1.4.3)
|
|
134
|
-
loofah (~> 2.3)
|
|
135
|
-
railties (7.0.4)
|
|
136
|
-
actionpack (= 7.0.4)
|
|
137
|
-
activesupport (= 7.0.4)
|
|
138
|
-
method_source
|
|
139
|
-
rake (>= 12.2)
|
|
140
|
-
thor (~> 1.0)
|
|
141
|
-
zeitwerk (~> 2.5)
|
|
142
10
|
rake (13.0.6)
|
|
143
11
|
rake-compiler (1.2.0)
|
|
144
12
|
rake
|
|
@@ -155,25 +23,15 @@ GEM
|
|
|
155
23
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
156
24
|
rspec-support (~> 3.11.0)
|
|
157
25
|
rspec-support (3.11.0)
|
|
158
|
-
strscan (3.0.4)
|
|
159
|
-
thor (1.2.1)
|
|
160
|
-
timeout (0.3.0)
|
|
161
|
-
tzinfo (2.0.5)
|
|
162
|
-
concurrent-ruby (~> 1.0)
|
|
163
|
-
websocket-driver (0.7.5)
|
|
164
|
-
websocket-extensions (>= 0.1.0)
|
|
165
|
-
websocket-extensions (0.1.5)
|
|
166
|
-
zeitwerk (2.6.0)
|
|
167
26
|
|
|
168
27
|
PLATFORMS
|
|
169
28
|
x86_64-linux
|
|
170
29
|
|
|
171
30
|
DEPENDENCIES
|
|
172
31
|
im!
|
|
173
|
-
rails
|
|
174
32
|
rake (~> 13.0)
|
|
175
33
|
rake-compiler
|
|
176
34
|
rspec (~> 3.0)
|
|
177
35
|
|
|
178
36
|
BUNDLED WITH
|
|
179
|
-
2.
|
|
37
|
+
2.3.18
|
data/README.md
CHANGED
|
@@ -24,8 +24,8 @@ require "im"
|
|
|
24
24
|
|
|
25
25
|
extend Im
|
|
26
26
|
|
|
27
|
-
mod = import "
|
|
28
|
-
#=>
|
|
27
|
+
mod = import "active_model"
|
|
28
|
+
#=> <#Im::Import root: active_model>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
Constants in the imported files are under the returned module, not the root namespace:
|
data/lib/im/kernel.rb
CHANGED
|
@@ -4,42 +4,16 @@ module Kernel
|
|
|
4
4
|
alias_method :im_original_require, :require
|
|
5
5
|
|
|
6
6
|
def require(path)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
!!Im.import(path)
|
|
10
|
-
end
|
|
7
|
+
Im.handle_require(path, caller_locations(1, 1).first.path) do
|
|
8
|
+
im_original_require(path)
|
|
11
9
|
end
|
|
10
|
+
end
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
resolved_path = resolved[1]
|
|
15
|
-
Im.registry[resolved_path] ||= Im::Dependency.new(resolved_path, Im.current_import)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
loaded = im_original_require(path)
|
|
19
|
-
return loaded unless Im.importing?
|
|
20
|
-
|
|
21
|
-
if resolved
|
|
22
|
-
dependency = Im.registry[resolved_path]
|
|
23
|
-
|
|
24
|
-
if loaded && Im.registry.key?(location = caller_locations(1, 1).first.path)
|
|
25
|
-
Im.registry[location].dependencies << dependency
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
dependency.dependencies.each { |d| require d.path }
|
|
29
|
-
|
|
30
|
-
dependency.modules.each do |m|
|
|
31
|
-
name = m.name
|
|
32
|
-
|
|
33
|
-
# Do not assign constants that are aliased to root namespace
|
|
34
|
-
root = name.split("::", 2)[0]
|
|
35
|
-
next if Object.const_defined?(root) &&
|
|
36
|
-
Im.current_import.const_defined?(root, false) &&
|
|
37
|
-
Object.const_get(root) == Im.current_import.const_get(root)
|
|
12
|
+
alias_method :im_original_autoload, :autoload
|
|
38
13
|
|
|
39
|
-
|
|
40
|
-
|
|
14
|
+
def autoload(name, path)
|
|
15
|
+
Im.handle_autoload(path) do
|
|
16
|
+
im_original_autoload(name, path)
|
|
41
17
|
end
|
|
42
|
-
|
|
43
|
-
return loaded
|
|
44
18
|
end
|
|
45
19
|
end
|
data/lib/im/module.rb
CHANGED
|
@@ -2,7 +2,8 @@ class Module
|
|
|
2
2
|
alias_method :im_original_autoload, :autoload
|
|
3
3
|
|
|
4
4
|
def autoload(name, path)
|
|
5
|
-
Im.
|
|
6
|
-
|
|
5
|
+
Im.handle_autoload(path) do
|
|
6
|
+
im_original_autoload(name, path)
|
|
7
|
+
end
|
|
7
8
|
end
|
|
8
9
|
end
|
data/lib/im/version.rb
CHANGED
data/lib/im.rb
CHANGED
|
@@ -1,38 +1,103 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Im
|
|
4
|
-
load
|
|
4
|
+
load $:.resolve_feature_path("im/ruby_version_check")[1], true
|
|
5
|
+
|
|
6
|
+
@toplevel_constants = Object.constants.reject { |c| Object.autoload?(c) }
|
|
7
|
+
@autoloads = {}
|
|
8
|
+
@registry = {}
|
|
9
|
+
@current_imports = []
|
|
10
|
+
|
|
5
11
|
require "im/version"
|
|
6
12
|
require "im/kernel"
|
|
7
13
|
|
|
8
14
|
class << self
|
|
9
|
-
attr_reader :
|
|
15
|
+
attr_reader :current_imports, :registry, :autoloads, :toplevel_constants
|
|
10
16
|
|
|
11
17
|
def with_import(import)
|
|
12
|
-
|
|
13
|
-
@current_import = import
|
|
18
|
+
@current_imports.push(import || current_import)
|
|
14
19
|
|
|
15
20
|
unless tracer_originally_enabled = @tracer.enabled?
|
|
16
21
|
@tracer.enable
|
|
17
22
|
end
|
|
18
23
|
|
|
19
|
-
yield
|
|
20
|
-
|
|
24
|
+
yield
|
|
21
25
|
ensure
|
|
22
|
-
@
|
|
26
|
+
@current_imports.pop
|
|
23
27
|
@tracer.disable unless tracer_originally_enabled
|
|
24
28
|
end
|
|
25
29
|
|
|
26
|
-
def
|
|
27
|
-
|
|
30
|
+
def current_import
|
|
31
|
+
current_imports.last
|
|
28
32
|
end
|
|
29
33
|
|
|
30
|
-
def
|
|
31
|
-
|
|
34
|
+
def importing?
|
|
35
|
+
!!current_import
|
|
32
36
|
end
|
|
33
37
|
|
|
34
|
-
def
|
|
35
|
-
|
|
38
|
+
def handle_require(path, caller_path)
|
|
39
|
+
resolved_path = resolve_path(path)
|
|
40
|
+
|
|
41
|
+
return yield unless resolved_path
|
|
42
|
+
|
|
43
|
+
if autoloaded = autoloads.delete(resolved_path)
|
|
44
|
+
return with_import(autoloaded) do
|
|
45
|
+
!!import(path)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if importing?
|
|
50
|
+
registry[resolved_path] ||= Require.new(resolved_path, current_import)
|
|
51
|
+
elsif registry.key?(caller_path)
|
|
52
|
+
return with_import(registry[caller_path].import) do
|
|
53
|
+
!!import(resolved_path)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
loaded = yield # super
|
|
58
|
+
|
|
59
|
+
if required = registry[resolved_path]
|
|
60
|
+
if loaded && registry.key?(caller_path)
|
|
61
|
+
registry[caller_path].requires << required
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
imports = importing? ? current_imports : [Object]
|
|
65
|
+
import_constants(required, imports)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
loaded
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def handle_autoload(path)
|
|
72
|
+
if importing? && (resolved_path = resolve_path(path))
|
|
73
|
+
autoloads[resolved_path] = current_import
|
|
74
|
+
end
|
|
75
|
+
yield
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def resolve_path(path)
|
|
79
|
+
(resolved = $:.resolve_feature_path(path)) && resolved[1]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def import_constants(required, imports)
|
|
83
|
+
return if imports.empty? || required.nil?
|
|
84
|
+
|
|
85
|
+
required.requires.each { |r| require r.path }
|
|
86
|
+
|
|
87
|
+
imports.each do |import|
|
|
88
|
+
required.defined_constants.each do |name, mod|
|
|
89
|
+
# Do not assign constants that are aliased to root namespace
|
|
90
|
+
root = name.to_s.split("::", 2)[0]
|
|
91
|
+
next if Object.const_defined?(root) &&
|
|
92
|
+
import.const_defined?(root, false) &&
|
|
93
|
+
Object.const_get(root) == import.const_get(root)
|
|
94
|
+
|
|
95
|
+
begin
|
|
96
|
+
import.const_set(name, mod) unless import.const_defined?(name, false)
|
|
97
|
+
rescue NameError
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
36
101
|
end
|
|
37
102
|
end
|
|
38
103
|
|
|
@@ -40,85 +105,89 @@ module Im
|
|
|
40
105
|
def initialize(root)
|
|
41
106
|
@root = root
|
|
42
107
|
super()
|
|
43
|
-
Im
|
|
44
|
-
|
|
108
|
+
Im.with_import(self) do
|
|
109
|
+
Im.toplevel_constants.each do |const|
|
|
110
|
+
self.const_set(const, Object.const_get(const))
|
|
111
|
+
end
|
|
45
112
|
end
|
|
46
113
|
end
|
|
47
114
|
|
|
48
115
|
def inspect
|
|
49
116
|
@inspect ||= "<#Im::Import root: #{@root}>"
|
|
50
117
|
end
|
|
118
|
+
|
|
119
|
+
def const_added(name)
|
|
120
|
+
path = const_source_location(name)[0]
|
|
121
|
+
value = const_get(name, false)
|
|
122
|
+
Im.registry[path] ||= Require.new(path, self)
|
|
123
|
+
Im.registry[path].defined_constants[name] ||= value
|
|
124
|
+
super
|
|
125
|
+
end
|
|
51
126
|
end
|
|
52
127
|
|
|
53
|
-
|
|
54
|
-
def initialize(path, import,
|
|
55
|
-
super
|
|
128
|
+
Require = Struct.new(:path, :import, :defined_constants, :requires) do
|
|
129
|
+
def initialize(path, import, defined_constants = {}, requires = [])
|
|
130
|
+
super
|
|
56
131
|
end
|
|
57
132
|
end
|
|
58
133
|
|
|
59
134
|
def import(path)
|
|
60
|
-
if resolved =
|
|
135
|
+
if resolved = $:.resolve_feature_path(path)
|
|
61
136
|
resolved_path = resolved[1]
|
|
62
137
|
raise LoadError, "import can only import ruby files" unless resolved[0] == :rb
|
|
63
138
|
else
|
|
64
139
|
raise LoadError, "cannot load such file -- #{path}"
|
|
65
140
|
end
|
|
66
141
|
|
|
67
|
-
Im.registry.fetch(resolved_path) do
|
|
142
|
+
required = Im.registry.fetch(resolved_path) do
|
|
68
143
|
# handle autoload within import
|
|
69
144
|
return nil if $LOADED_FEATURES.include?(resolved_path)
|
|
70
145
|
|
|
71
146
|
$LOADED_FEATURES << resolved_path
|
|
72
147
|
|
|
73
148
|
import = Im.current_import || Import.new(path)
|
|
74
|
-
(Im.registry[resolved_path] ||=
|
|
149
|
+
(Im.registry[resolved_path] ||= Require.new(resolved_path, import)).tap do
|
|
75
150
|
Im.with_import(import) do
|
|
76
151
|
load resolved_path, import
|
|
77
152
|
end
|
|
78
153
|
end
|
|
79
|
-
end&.import
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# This is a hack to catch references to top-level constants (`::Foo`) and, if
|
|
83
|
-
# the calling line is a key in the Im registry, replace the toplevel constant
|
|
84
|
-
# reference with its corresponding constant under the import namespace.
|
|
85
|
-
#
|
|
86
|
-
# By doing this, a reference to `::Foo` in an imported file will resolve to
|
|
87
|
-
# `mod::Foo`, where `mod` is the import module. Ideally this should
|
|
88
|
-
# ultimately happen at the Ruby implementation level.
|
|
89
|
-
module RootNamespaceRedirect
|
|
90
|
-
def const_missing(name)
|
|
91
|
-
|
|
92
|
-
# Take top five locations to allow for other `const_missing` overrides
|
|
93
|
-
# in the backtrace. If there are more than five, then this will no longer
|
|
94
|
-
# work. This is currently very inefficient.
|
|
95
|
-
if location = caller_locations(1, 5).find { |l| Im.registry.key?(l.path) }
|
|
96
|
-
Im.registry[location.path].import.const_get(name)
|
|
97
|
-
else
|
|
98
|
-
super
|
|
99
|
-
end
|
|
100
154
|
end
|
|
155
|
+
|
|
156
|
+
Im.import_constants(required, Im.current_imports)
|
|
157
|
+
|
|
158
|
+
required&.import
|
|
101
159
|
end
|
|
102
160
|
|
|
103
161
|
@tracer = TracePoint.new(:class) do |event|
|
|
104
|
-
next unless (name = event.self.name)
|
|
105
|
-
next if Im
|
|
106
|
-
|
|
107
|
-
|
|
162
|
+
next unless (name = event.self.name&.to_sym)
|
|
163
|
+
next if Im.toplevel_constants.include?(name)
|
|
164
|
+
|
|
165
|
+
# We don't want to track classes defined under singleton classes, like
|
|
166
|
+
# this:
|
|
167
|
+
#
|
|
168
|
+
# class Foo
|
|
169
|
+
# class << self
|
|
170
|
+
# class Bar
|
|
171
|
+
# end
|
|
172
|
+
# end
|
|
173
|
+
# end
|
|
174
|
+
#
|
|
175
|
+
# Here, `class Bar` will trigger a TracePoint event, and because of the
|
|
176
|
+
# Ruby patch `name` will return "Bar", but this is not actually a class we
|
|
177
|
+
# need to alias in imports, so we can safely skip it. The only way I've
|
|
178
|
+
# found to do that though is to evaluate `Module.nesting` from the event's
|
|
179
|
+
# binding. This is weird, but it works!
|
|
180
|
+
#
|
|
181
|
+
next if event.binding.eval("Module.nesting").any?(&:singleton_class?)
|
|
182
|
+
|
|
183
|
+
if resolved = $:.resolve_feature_path(event.path)
|
|
108
184
|
resolved_path = resolved[1]
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
else
|
|
112
|
-
Im.registry[resolved_path] = Dependency.new(resolved_path, Im.current_import, [event.self])
|
|
113
|
-
end
|
|
185
|
+
Im.registry[resolved_path] ||= Require.new(resolved_path, Im.current_import)
|
|
186
|
+
Im.registry[resolved_path].defined_constants[name] = event.self
|
|
114
187
|
end
|
|
115
188
|
end
|
|
116
189
|
|
|
117
190
|
require "im/module"
|
|
118
|
-
require "im/autoload"
|
|
119
|
-
require "im/constants"
|
|
120
191
|
|
|
121
192
|
extend self
|
|
122
193
|
end
|
|
123
|
-
|
|
124
|
-
Object.extend Im::RootNamespaceRedirect
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: im
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Salzberg
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-10-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -66,8 +66,6 @@ files:
|
|
|
66
66
|
- README.md
|
|
67
67
|
- Rakefile
|
|
68
68
|
- lib/im.rb
|
|
69
|
-
- lib/im/autoload.rb
|
|
70
|
-
- lib/im/constants.rb
|
|
71
69
|
- lib/im/kernel.rb
|
|
72
70
|
- lib/im/module.rb
|
|
73
71
|
- lib/im/ruby_version_check.rb
|
|
@@ -96,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
96
94
|
- !ruby/object:Gem::Version
|
|
97
95
|
version: '0'
|
|
98
96
|
requirements: []
|
|
99
|
-
rubygems_version: 3.
|
|
97
|
+
rubygems_version: 3.3.7
|
|
100
98
|
signing_key:
|
|
101
99
|
specification_version: 4
|
|
102
100
|
summary: Module import system.
|
data/lib/im/autoload.rb
DELETED
data/lib/im/constants.rb
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
module Im
|
|
2
|
-
# It's faster to just hard-code constants than to introspect them at runtime
|
|
3
|
-
CONSTANTS = [
|
|
4
|
-
:ArgumentError,
|
|
5
|
-
:Array,
|
|
6
|
-
:BasicObject,
|
|
7
|
-
:Binding,
|
|
8
|
-
:Class,
|
|
9
|
-
:ClosedQueueError,
|
|
10
|
-
:Comparable,
|
|
11
|
-
:Complex,
|
|
12
|
-
:ConditionVariable,
|
|
13
|
-
:DidYouMean,
|
|
14
|
-
:Dir,
|
|
15
|
-
:Encoding,
|
|
16
|
-
:EncodingError,
|
|
17
|
-
:Enumerable,
|
|
18
|
-
:Enumerator,
|
|
19
|
-
:EOFError,
|
|
20
|
-
:Errno,
|
|
21
|
-
:ErrorHighlight,
|
|
22
|
-
:Exception,
|
|
23
|
-
:FalseClass,
|
|
24
|
-
:Fiber,
|
|
25
|
-
:FiberError,
|
|
26
|
-
:File,
|
|
27
|
-
:FileTest,
|
|
28
|
-
:Float,
|
|
29
|
-
:FloatDomainError,
|
|
30
|
-
:FrozenError,
|
|
31
|
-
:GC,
|
|
32
|
-
:Gem,
|
|
33
|
-
:Hash,
|
|
34
|
-
:IndexError,
|
|
35
|
-
:Integer,
|
|
36
|
-
:Interrupt,
|
|
37
|
-
:IO,
|
|
38
|
-
:IOError,
|
|
39
|
-
:Kernel,
|
|
40
|
-
:KeyError,
|
|
41
|
-
:LoadError,
|
|
42
|
-
:LocalJumpError,
|
|
43
|
-
:Marshal,
|
|
44
|
-
:MatchData,
|
|
45
|
-
:Math,
|
|
46
|
-
:Method,
|
|
47
|
-
:Module,
|
|
48
|
-
:Monitor,
|
|
49
|
-
:MonitorMixin,
|
|
50
|
-
:Mutex,
|
|
51
|
-
:NameError,
|
|
52
|
-
:NilClass,
|
|
53
|
-
:NoMatchingPatternError,
|
|
54
|
-
:NoMatchingPatternKeyError,
|
|
55
|
-
:NoMemoryError,
|
|
56
|
-
:NoMethodError,
|
|
57
|
-
:NotImplementedError,
|
|
58
|
-
:Numeric,
|
|
59
|
-
:Object,
|
|
60
|
-
:ObjectSpace,
|
|
61
|
-
:Proc,
|
|
62
|
-
:Process,
|
|
63
|
-
:Queue,
|
|
64
|
-
:Ractor,
|
|
65
|
-
:Random,
|
|
66
|
-
:Range,
|
|
67
|
-
:RangeError,
|
|
68
|
-
:Rational,
|
|
69
|
-
:RbConfig,
|
|
70
|
-
:Refinement,
|
|
71
|
-
:Regexp,
|
|
72
|
-
:RegexpError,
|
|
73
|
-
:RubyVM,
|
|
74
|
-
:RuntimeError,
|
|
75
|
-
:ScriptError,
|
|
76
|
-
:SecurityError,
|
|
77
|
-
:Set,
|
|
78
|
-
:Signal,
|
|
79
|
-
:SignalException,
|
|
80
|
-
:SizedQueue,
|
|
81
|
-
:StandardError,
|
|
82
|
-
:StopIteration,
|
|
83
|
-
:String,
|
|
84
|
-
:Struct,
|
|
85
|
-
:Symbol,
|
|
86
|
-
:SyntaxError,
|
|
87
|
-
:SystemCallError,
|
|
88
|
-
:SystemExit,
|
|
89
|
-
:SystemStackError,
|
|
90
|
-
:Thread,
|
|
91
|
-
:ThreadError,
|
|
92
|
-
:ThreadGroup,
|
|
93
|
-
:Time,
|
|
94
|
-
:TracePoint,
|
|
95
|
-
:TrueClass,
|
|
96
|
-
:TypeError,
|
|
97
|
-
:UnboundMethod,
|
|
98
|
-
:UncaughtThrowError,
|
|
99
|
-
:UnicodeNormalize,
|
|
100
|
-
:URI,
|
|
101
|
-
:Warning,
|
|
102
|
-
:ZeroDivisionError,
|
|
103
|
-
]
|
|
104
|
-
end
|