Skip to content

Commit

Permalink
Simplify the eager load (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper authored Feb 4, 2025
1 parent 0c94fd5 commit db29f67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
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

0 comments on commit db29f67

Please sign in to comment.