Skip to content

Commit

Permalink
Rename set_autoload → define_autoload
Browse files Browse the repository at this point in the history
Was never fully convinced by "set". Perhaps "define" is a better choice.
  • Loading branch information
fxn committed Sep 25, 2023
1 parent 7f56fa8 commit aa5c587
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lib/zeitwerk/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def setup
break if @setup

actual_roots.each do |root_dir, root_namespace|
set_autoloads_in_dir(root_dir, root_namespace)
define_autoloads_in_dir(root_dir, root_namespace)
end

on_setup_callbacks.each(&:call)
Expand Down Expand Up @@ -407,14 +407,14 @@ def all_dirs
end

# @sig (String, Module) -> void
private def set_autoloads_in_dir(dir, parent)
private def define_autoloads_in_dir(dir, parent)
ls(dir) do |basename, abspath|
if ruby?(basename)
basename.delete_suffix!(".rb")
autoload_file(parent, cname_for(basename, abspath), abspath)
else
if collapse?(abspath)
set_autoloads_in_dir(abspath, parent)
define_autoloads_in_dir(abspath, parent)
else
autoload_subdir(parent, cname_for(basename, abspath), abspath)
end
Expand Down Expand Up @@ -443,12 +443,12 @@ def all_dirs
elsif !cdef?(parent, cname)
# First time we find this namespace, set an autoload for it.
namespace_dirs[cpath(parent, cname)] << subdir
set_autoload(parent, cname, subdir)
define_autoload(parent, cname, subdir)
else
# For whatever reason the constant that corresponds to this namespace has
# already been defined, we have to recurse.
log("the namespace #{cpath(parent, cname)} already exists, descending into #{subdir}") if logger
set_autoloads_in_dir(subdir, cget(parent, cname))
define_autoloads_in_dir(subdir, cget(parent, cname))
end
end

Expand All @@ -471,7 +471,7 @@ def all_dirs
shadowed_files << file
log("file #{file} is ignored because #{cpath(parent, cname)} is already defined") if logger
else
set_autoload(parent, cname, file)
define_autoload(parent, cname, file)
end
end

Expand All @@ -485,12 +485,12 @@ def all_dirs

log("earlier autoload for #{cpath(parent, cname)} discarded, it is actually an explicit namespace defined in #{file}") if logger

set_autoload(parent, cname, file)
define_autoload(parent, cname, file)
register_explicit_namespace(cpath(parent, cname))
end

# @sig (Module, Symbol, String) -> void
private def set_autoload(parent, cname, abspath)
private def define_autoload(parent, cname, abspath)
parent.autoload(cname, abspath)

if logger
Expand Down
2 changes: 1 addition & 1 deletion lib/zeitwerk/loader/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module Zeitwerk::Loader::Callbacks
def on_namespace_loaded(namespace)
if dirs = namespace_dirs.delete(real_mod_name(namespace))
dirs.each do |dir|
set_autoloads_in_dir(dir, namespace)
define_autoloads_in_dir(dir, namespace)
end
end
end
Expand Down

0 comments on commit aa5c587

Please sign in to comment.