Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the eager load #843

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions config/quickdraw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,9 @@

Bundler.require :test

module AutoloadRecorder
AUTOLOADS = []

def self.load_all
AUTOLOADS.each do |(mod, name)|
mod.const_get(name)
end
end

def autoload(name, path)
super
::AutoloadRecorder::AUTOLOADS << [self, name].freeze
end
end

Module.prepend(AutoloadRecorder)

require "phlex"

AutoloadRecorder.load_all
Phlex.eager_load

# Previous content of test helper now starts here
$LOAD_PATH.unshift(File.expand_path("../fixtures", __dir__))
11 changes: 11 additions & 0 deletions lib/phlex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def self.__expand_attribute_cache__(file_path)
Phlex::ATTRIBUTE_CACHE.expand(File.size(file_path))
end
end

def self.eager_load
queue = [self]

while (mod = queue.shift)
mod.constants.each do |const_name|
const = mod.const_get(const_name)
queue << const if Module === const
end
end
end
end

def 💪
Expand Down