dirload 0.7.4 → 0.7.5

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dirload.rb +16 -1
  3. data/lib/loader.rb +14 -1
  4. data/lib/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84947a06acc71325c32000a7f633a3217fe94f13d61e09297f319ac7c34e4845
4
- data.tar.gz: 3bba94dd297cb6fe5971c30c16ff43a560b7ef5e50ff4fb70b132b88eae61c52
3
+ metadata.gz: 25766cbcbc524cd3067f7b10e2c1895271e6c9ac046b4a113e2cd8b6fcd0e7ca
4
+ data.tar.gz: 78438a0fd5fb6a29ad7faae923baa60ca6a1be41c9b78ee5da26f720cd63251f
5
5
  SHA512:
6
- metadata.gz: 78db695fe48228db71026cbd40d7cabd1f5799669f59c2e3a18248d93aa4f5e8293a977616901534a96afdbc76722c34cd6c23b776a0792bbb957f6f83eada3b
7
- data.tar.gz: dc343eb1ae07953d2ebafe170ed9cc066230ad37737cb226f8257b8aea0a433d75bdf77ae8b383f4bef0682c437ca02454d71015c7bace62d5fc174ecfd3ef41
6
+ metadata.gz: bf6d73ac50b7cf6be3e8ff27c595cafe6e85bb3e2b9ce95503c1a6c0e17bff8fcf729072d058343274242294b6945980fb1159a61d600dae12d9f5afa8954dc9
7
+ data.tar.gz: 1f08ba17f1dd58c47b665f702b5c5d021c543b08a5dff543541760a43eab0492f57c515f608bddfc29e3e4b23a7b2e33c6c8ca31560de152561044b412791707
data/lib/dirload.rb CHANGED
@@ -54,7 +54,7 @@ module Dirload
54
54
  Dirload.step(:mapload, loaded_paths:)
55
55
  Unloader.track(path: absolute_path, loaded_paths:)
56
56
  Dirload.step(:preload, loaded_paths:)
57
- Dirload.step(:evaluate, loaded_paths:)
57
+ Dirload.evaluate(loaded_paths:)
58
58
 
59
59
  Metadata.new(loaded_paths:, missed_paths:, file_types:)
60
60
  end
@@ -77,6 +77,21 @@ module Dirload
77
77
  adapter.evaluate(file_path:)
78
78
  end
79
79
 
80
+ # Evaluates each file after the RBX files it uses, as autoload only loads Ruby files.
81
+ def evaluate(loaded_paths:)
82
+ evaluated = Set.new
83
+ loaded_paths.each_key { |file_path| evaluate_once(file_path:, loaded_paths:, evaluated:) }
84
+ end
85
+
86
+ def evaluate_once(file_path:, loaded_paths:, evaluated:)
87
+ return unless evaluated.add?(file_path)
88
+
89
+ Loader.rbx_paths(file_proxy: Lowkey[file_path]).each do |rbx_path|
90
+ evaluate_once(file_path: rbx_path, loaded_paths:, evaluated:) if loaded_paths.key?(rbx_path)
91
+ end
92
+ loaded_paths[file_path].evaluate(file_path:)
93
+ end
94
+
80
95
  def step(step, loaded_paths:)
81
96
  loaded_paths.each do |file_path, adapter|
82
97
  adapter&.send(step, file_path:)
data/lib/loader.rb CHANGED
@@ -8,7 +8,7 @@ module Dirload
8
8
  def add_autoloads(file_proxy:)
9
9
  file_proxy.dependencies.filter_map do |dependency|
10
10
  name, dependency_proxy = definition(dependency:)
11
- # Ruby autoloads with require, which only loads Ruby files, so an RBX file's classes load in their turn.
11
+ # Ruby autoloads with require which only loads Ruby files so RBX files are evaluated first instead.
12
12
  next unless dependency_proxy&.file_path&.end_with?('.rb') && !dependency_proxy.equal?(file_proxy)
13
13
 
14
14
  parent_name, _, constant = name.rpartition('::')
@@ -21,6 +21,19 @@ module Dirload
21
21
  end
22
22
  end
23
23
 
24
+ # The RBX files a file uses directly or through the Ruby files it uses. Autoload can't load them so they're evaluated first.
25
+ def rbx_paths(file_proxy:, seen: Set.new)
26
+ return [] unless file_proxy && seen.add?(file_proxy)
27
+
28
+ file_proxy.dependencies.flat_map do |dependency|
29
+ _, dependency_proxy = definition(dependency:)
30
+ next [] if dependency_proxy.nil? || dependency_proxy.equal?(file_proxy)
31
+ next [dependency_proxy.file_path] if dependency_proxy.file_path.end_with?('.rbx')
32
+
33
+ rbx_paths(file_proxy: dependency_proxy, seen:)
34
+ end.uniq
35
+ end
36
+
24
37
  private
25
38
 
26
39
  # Where a constant used in a namespace is defined, as Ruby looks it up. "Shelf::Tag" is Shelf::Tag if a file
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dirload
4
- VERSION = '0.7.4'
4
+ VERSION = '0.7.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi