Merge pull request #14590 from Homebrew/dependabot/bundler/Library/Homebrew/zeitwerk-2.6.7

build(deps): bump zeitwerk from 2.6.6 to 2.6.7 in /Library/Homebrew
This commit is contained in:
Mike McQuaid 2023-02-10 19:39:53 +00:00 committed by GitHub
commit 13e5a0972c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 92 additions and 51 deletions

View File

@ -215,7 +215,7 @@ GEM
yard-sorbet (0.6.1)
sorbet-runtime (>= 0.5)
yard (>= 0.9)
zeitwerk (2.6.6)
zeitwerk (2.6.7)
PLATFORMS
aarch64-linux

View File

@ -29,6 +29,7 @@ module Zeitwerk::ExplicitNamespace
class << self
def __register(cpath, loader); end
def __registered?(cpath); end
def __unregister_loader(loader); end
private
@ -37,6 +38,7 @@ module Zeitwerk::ExplicitNamespace
def disable_tracer_if_unneeded; end
def mutex; end
def register(cpath, loader); end
def registered?(cpath); end
def tracepoint_class_callback(event); end
def tracer; end
def unregister_loader(loader); end
@ -82,19 +84,18 @@ class Zeitwerk::Loader
include ::Zeitwerk::Loader::Helpers
include ::Zeitwerk::Loader::Config
include ::Zeitwerk::Loader::EagerLoad
extend ::Zeitwerk::Internal
def initialize; end
def autoloaded_dirs; end
def autoloads; end
def mutex; end
def mutex2; end
def namespace_dirs; end
def __autoloaded_dirs; end
def __autoloads; end
def __namespace_dirs; end
def __shadowed_file?(file); end
def __shadowed_files; end
def __to_unload; end
def reload; end
def setup; end
def shadowed_file?(file); end
def shadowed_files; end
def to_unload; end
def unload; end
def unloadable_cpath?(cpath); end
def unloadable_cpaths; end
@ -105,12 +106,20 @@ class Zeitwerk::Loader
def autoload_file(parent, cname, file); end
def autoload_path_set_by_me_for?(parent, cname); end
def autoload_subdir(parent, cname, subdir); end
def autoloaded_dirs; end
def autoloads; end
def mutex; end
def mutex2; end
def namespace_dirs; end
def promote_namespace_from_implicit_to_explicit(dir:, file:, parent:, cname:); end
def raise_if_conflicting_directory(dir); end
def register_explicit_namespace(cpath); end
def run_on_unload_callbacks(cpath, value, abspath); end
def set_autoload(parent, cname, abspath); end
def set_autoloads_in_dir(dir, parent); end
def shadowed_file?(file); end
def shadowed_files; end
def to_unload; end
def unload_autoload(parent, cname); end
def unload_cref(parent, cname); end
@ -145,7 +154,7 @@ module Zeitwerk::Loader::Config
def __ignores?(abspath); end
def __roots; end
def collapse(*glob_patterns); end
def dirs(namespaces: T.unsafe(nil)); end
def dirs(namespaces: T.unsafe(nil), ignored: T.unsafe(nil)); end
def do_not_eager_load(*paths); end
def enable_reloading; end
def ignore(*glob_patterns); end
@ -203,6 +212,7 @@ module Zeitwerk::Loader::Helpers
def cdef?(parent, cname); end
def cget(parent, cname); end
def cpath(parent, cname); end
def crem(parent, cname); end
def dir?(path); end
def has_at_least_one_ruby_file?(dir); end
def hidden?(basename); end

View File

@ -27,7 +27,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/i18n-1.12.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/minitest-5.17.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/tzinfo-2.0.6/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/zeitwerk-2.6.6/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/zeitwerk-2.6.7/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/activesupport-6.1.7.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/public_suffix-5.0.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/addressable-2.8.1/lib")

View File

@ -47,6 +47,13 @@ module Zeitwerk
disable_tracer_if_unneeded
end
# This is an internal method only used by the test suite.
#
# @sig (String) -> bool
internal def registered?(cpath)
cpaths.key?(cpath)
end
# @sig () -> void
private def disable_tracer_if_unneeded
mutex.synchronize do

View File

@ -9,6 +9,8 @@ module Zeitwerk
require_relative "loader/config"
require_relative "loader/eager_load"
extend Internal
include RealModName
include Callbacks
include Helpers
@ -26,9 +28,9 @@ module Zeitwerk
# "/Users/fxn/blog/app/models/hotel/pricing.rb" => [Hotel, :Pricing]
# ...
#
# @private
# @sig Hash[String, [Module, Symbol]]
attr_reader :autoloads
internal :autoloads
# We keep track of autoloaded directories to remove them from the registry
# at the end of eager loading.
@ -36,9 +38,9 @@ module Zeitwerk
# Files are removed as they are autoloaded, but directories need to wait due
# to concurrency (see why in Zeitwerk::Loader::Callbacks#on_dir_autoloaded).
#
# @private
# @sig Array[String]
attr_reader :autoloaded_dirs
internal :autoloaded_dirs
# Stores metadata needed for unloading. Its entries look like this:
#
@ -52,9 +54,9 @@ module Zeitwerk
# If reloading is enabled, this hash is filled as constants are autoloaded
# or eager loaded. Otherwise, the collection remains empty.
#
# @private
# @sig Hash[String, [String, [Module, Symbol]]]
attr_reader :to_unload
internal :to_unload
# Maps namespace constant paths to their respective directories.
#
@ -70,9 +72,9 @@ module Zeitwerk
# and that its children are spread over those directories. We'll visit them
# to set up the corresponding autoloads.
#
# @private
# @sig Hash[String, Array[String]]
attr_reader :namespace_dirs
internal :namespace_dirs
# A shadowed file is a file managed by this loader that is ignored when
# setting autoloads because its matching constant is already taken.
@ -81,17 +83,17 @@ module Zeitwerk
# has only scanned the top-level, `shadowed_files` does not have shadowed
# files that may exist deep in the project tree yet.
#
# @private
# @sig Set[String]
attr_reader :shadowed_files
internal :shadowed_files
# @private
# @sig Mutex
attr_reader :mutex
private :mutex
# @private
# @sig Mutex
attr_reader :mutex2
private :mutex2
def initialize
super
@ -134,7 +136,7 @@ module Zeitwerk
# unload them.
#
# This method is public but undocumented. Main interface is `reload`, which
# means `unload` + `setup`. This one is avaiable to be used together with
# means `unload` + `setup`. This one is available to be used together with
# `unregister`, which is undocumented too.
#
# @sig () -> void
@ -254,9 +256,8 @@ module Zeitwerk
# The return value of this predicate is only meaningful if the loader has
# scanned the file. This is the case in the spots where we use it.
#
# @private
# @sig (String) -> Boolean
def shadowed_file?(file)
internal def shadowed_file?(file)
shadowed_files.member?(file)
end
@ -323,10 +324,8 @@ module Zeitwerk
end
end
private # -------------------------------------------------------------------------------------
# @sig (String, Module) -> void
def set_autoloads_in_dir(dir, parent)
private def set_autoloads_in_dir(dir, parent)
ls(dir) do |basename, abspath|
begin
if ruby?(basename)
@ -361,13 +360,22 @@ module Zeitwerk
end
# @sig (Module, Symbol, String) -> void
def autoload_subdir(parent, cname, subdir)
private def autoload_subdir(parent, cname, subdir)
if autoload_path = autoload_path_set_by_me_for?(parent, cname)
cpath = cpath(parent, cname)
register_explicit_namespace(cpath) if ruby?(autoload_path)
# We do not need to issue another autoload, the existing one is enough
# no matter if it is for a file or a directory. Just remember the
# subdirectory has to be visited if the namespace is used.
if ruby?(autoload_path)
# Scanning visited a Ruby file first, and now a directory for the same
# constant has been found. This means we are dealing with an explicit
# namespace whose definition was seen first.
#
# Registering is idempotent, and we have to keep the autoload pointing
# to the file. This may run again if more directories are found later
# on, no big deal.
register_explicit_namespace(cpath)
end
# If the existing autoload points to a file, it has to be preserved, if
# not, it is fine as it is. In either case, we do not need to override.
# Just remember the subdirectory conforms this namespace.
namespace_dirs[cpath] << subdir
elsif !cdef?(parent, cname)
# First time we find this namespace, set an autoload for it.
@ -382,7 +390,7 @@ module Zeitwerk
end
# @sig (Module, Symbol, String) -> void
def autoload_file(parent, cname, file)
private def autoload_file(parent, cname, file)
if autoload_path = strict_autoload_path(parent, cname) || Registry.inception?(cpath(parent, cname))
# First autoload for a Ruby file wins, just ignore subsequent ones.
if ruby?(autoload_path)
@ -408,7 +416,7 @@ module Zeitwerk
# the file where we've found the namespace is explicitly defined.
#
# @sig (dir: String, file: String, parent: Module, cname: Symbol) -> void
def promote_namespace_from_implicit_to_explicit(dir:, file:, parent:, cname:)
private def promote_namespace_from_implicit_to_explicit(dir:, file:, parent:, cname:)
autoloads.delete(dir)
Registry.unregister_autoload(dir)
@ -419,7 +427,7 @@ module Zeitwerk
end
# @sig (Module, Symbol, String) -> void
def set_autoload(parent, cname, abspath)
private def set_autoload(parent, cname, abspath)
parent.autoload(cname, abspath)
if logger
@ -440,7 +448,7 @@ module Zeitwerk
end
# @sig (Module, Symbol) -> String?
def autoload_path_set_by_me_for?(parent, cname)
private def autoload_path_set_by_me_for?(parent, cname)
if autoload_path = strict_autoload_path(parent, cname)
autoload_path if autoloads.key?(autoload_path)
else
@ -449,12 +457,12 @@ module Zeitwerk
end
# @sig (String) -> void
def register_explicit_namespace(cpath)
private def register_explicit_namespace(cpath)
ExplicitNamespace.__register(cpath, self)
end
# @sig (String) -> void
def raise_if_conflicting_directory(dir)
private def raise_if_conflicting_directory(dir)
MUTEX.synchronize do
dir_slash = dir + "/"
@ -479,23 +487,23 @@ module Zeitwerk
end
# @sig (String, Object, String) -> void
def run_on_unload_callbacks(cpath, value, abspath)
private def run_on_unload_callbacks(cpath, value, abspath)
# Order matters. If present, run the most specific one.
on_unload_callbacks[cpath]&.each { |c| c.call(value, abspath) }
on_unload_callbacks[:ANY]&.each { |c| c.call(cpath, value, abspath) }
end
# @sig (Module, Symbol) -> void
def unload_autoload(parent, cname)
parent.__send__(:remove_const, cname)
private def unload_autoload(parent, cname)
crem(parent, cname)
log("autoload for #{cpath(parent, cname)} removed") if logger
end
# @sig (Module, Symbol) -> void
def unload_cref(parent, cname)
private def unload_cref(parent, cname)
# Let's optimistically remove_const. The way we use it, this is going to
# succeed always if all is good.
parent.__send__(:remove_const, cname)
crem(parent, cname)
rescue ::NameError
# There are a few edge scenarios in which this may happen. If the constant
# is gone, that is OK, anyway.

View File

@ -11,18 +11,18 @@ module Zeitwerk::Loader::Callbacks
cref = autoloads.delete(file)
cpath = cpath(*cref)
# If reloading is enabled, we need to put this constant for unloading
# regardless of what cdef? says. In Ruby < 3.1 the internal state is not
# fully cleared. Module#constants still includes it, and you need to
# remove_const. See https://github.com/ruby/ruby/pull/4715.
to_unload[cpath] = [file, cref] if reloading_enabled?
Zeitwerk::Registry.unregister_autoload(file)
if cdef?(*cref)
log("constant #{cpath} loaded from file #{file}") if logger
to_unload[cpath] = [file, cref] if reloading_enabled?
run_on_load_callbacks(cpath, cget(*cref), file) unless on_load_callbacks.empty?
else
raise Zeitwerk::NameError.new("expected file #{file} to define constant #{cpath}, but didn't", cref.last)
msg = "expected file #{file} to define constant #{cpath}, but didn't"
log(msg) if logger
crem(*cref)
to_unload[cpath] = [file, cref] if reloading_enabled?
raise Zeitwerk::NameError.new(msg, cref.last)
end
end

View File

@ -149,14 +149,24 @@ module Zeitwerk::Loader::Config
# instead. Keys are the absolute paths of the root directories as strings,
# values are their corresponding namespaces, class or module objects.
#
# If `ignored` is falsey (default), ignored root directories are filtered out.
#
# These are read-only collections, please add to them with `push_dir`.
#
# @sig () -> Array[String] | Hash[String, Module]
def dirs(namespaces: false)
def dirs(namespaces: false, ignored: false)
if namespaces
if ignored || ignored_paths.empty?
roots.clone
else
roots.reject { |root_dir, _namespace| ignored_path?(root_dir) }
end
else
if ignored || ignored_paths.empty?
roots.keys
else
roots.keys.reject { |root_dir| ignored_path?(root_dir) }
end
end.freeze
end

View File

@ -183,7 +183,7 @@ module Zeitwerk::Loader::EagerLoad
end
# In order to invoke this method, the caller has to ensure `child` is a
# strict namespace descendendant of `root_namespace`.
# strict namespace descendant of `root_namespace`.
#
# @sig (Module, String, Module, Boolean) -> void
private def eager_load_child_namespace(child, child_name, root_dir, root_namespace)

View File

@ -134,4 +134,10 @@ module Zeitwerk::Loader::Helpers
private def cget(parent, cname)
parent.const_get(cname, false)
end
# @raise [NameError]
# @sig (Module, Symbol) -> Object
private def crem(parent, cname)
parent.__send__(:remove_const, cname)
end
end

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module Zeitwerk
VERSION = "2.6.6"
VERSION = "2.6.7"
end