brew vendor-gems: commit updates.

This commit is contained in:
BrewTestBot 2022-11-08 18:07:43 +00:00
parent 9423e78242
commit 1807e1a147
No known key found for this signature in database
GPG Key ID: 82D7D104050B0F0F
17 changed files with 78 additions and 46 deletions

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.16.3/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/tzinfo-2.0.5/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/zeitwerk-2.6.4/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/activesupport-6.1.7/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/public_suffix-5.0.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/addressable-2.8.1/lib")

View File

@ -12,4 +12,10 @@ module Zeitwerk
class NameError < ::NameError
end
class SetupRequired < Error
def initialize
super("please, finish your configuration and call Zeitwerk::Loader#setup once all is ready")
end
end
end

View File

@ -11,28 +11,28 @@ module Zeitwerk
module ExplicitNamespace # :nodoc: all
class << self
include RealModName
extend Internal
# Maps constant paths that correspond to explicit namespaces according to
# the file system, to the loader responsible for them.
#
# @private
# @sig Hash[String, Zeitwerk::Loader]
attr_reader :cpaths
private :cpaths
# @private
# @sig Mutex
attr_reader :mutex
private :mutex
# @private
# @sig TracePoint
attr_reader :tracer
private :tracer
# Asserts `cpath` corresponds to an explicit namespace for which `loader`
# is responsible.
#
# @private
# @sig (String, Zeitwerk::Loader) -> void
def register(cpath, loader)
internal def register(cpath, loader)
mutex.synchronize do
cpaths[cpath] = loader
# We check enabled? because, looking at the C source code, enabling an
@ -41,24 +41,21 @@ module Zeitwerk
end
end
# @private
# @sig (Zeitwerk::Loader) -> void
def unregister_loader(loader)
internal def unregister_loader(loader)
cpaths.delete_if { |_cpath, l| l == loader }
disable_tracer_if_unneeded
end
private
# @sig () -> void
def disable_tracer_if_unneeded
private def disable_tracer_if_unneeded
mutex.synchronize do
tracer.disable if cpaths.empty?
end
end
# @sig (TracePoint) -> void
def tracepoint_class_callback(event)
private def tracepoint_class_callback(event)
# If the class is a singleton class, we won't do anything with it so we
# can bail out immediately. This is several orders of magnitude faster
# than accessing its name.

View File

@ -109,7 +109,7 @@ module Zeitwerk
Registry.register_loader(self)
end
# Sets autoloads in the root namespace.
# Sets autoloads in the root namespaces.
#
# @sig () -> void
def setup
@ -140,6 +140,8 @@ module Zeitwerk
# @sig () -> void
def unload
mutex.synchronize do
raise SetupRequired unless @setup
# We are going to keep track of the files that were required by our
# autoloads to later remove them from $LOADED_FEATURES, thus making them
# loadable by Kernel#require again.
@ -199,7 +201,7 @@ module Zeitwerk
shadowed_files.clear
Registry.on_unload(self)
ExplicitNamespace.unregister_loader(self)
ExplicitNamespace.__unregister_loader(self)
@setup = false
@eager_loaded = false
@ -216,6 +218,7 @@ module Zeitwerk
# @sig () -> void
def reload
raise ReloadingDisabledError unless reloading_enabled?
raise SetupRequired unless @setup
unload
recompute_ignored_paths
@ -245,7 +248,7 @@ module Zeitwerk
# @sig () -> void
def unregister
Registry.unregister_loader(self)
ExplicitNamespace.unregister_loader(self)
ExplicitNamespace.__unregister_loader(self)
end
# The return value of this predicate is only meaningful if the loader has
@ -283,19 +286,31 @@ module Zeitwerk
Registry.loader_for_gem(called_from, warn_on_extra_files: warn_on_extra_files)
end
# Broadcasts `eager_load` to all loaders.
# Broadcasts `eager_load` to all loaders. Those that have not been setup
# are skipped.
#
# @sig () -> void
def eager_load_all
Registry.loaders.each(&:eager_load)
Registry.loaders.each do |loader|
begin
loader.eager_load
rescue SetupRequired
# This is fine, we eager load what can be eager loaded.
end
end
end
# Broadcasts `eager_load_namespace` to all loaders.
# Broadcasts `eager_load_namespace` to all loaders. Those that have not
# been setup are skipped.
#
# @sig (Module) -> void
def eager_load_namespace(mod)
Registry.loaders.each do |loader|
loader.eager_load_namespace(mod)
begin
loader.eager_load_namespace(mod)
rescue SetupRequired
# This is fine, we eager load what can be eager loaded.
end
end
end
@ -435,7 +450,7 @@ module Zeitwerk
# @sig (String) -> void
def register_explicit_namespace(cpath)
ExplicitNamespace.register(cpath, self)
ExplicitNamespace.__register(cpath, self)
end
# @sig (String) -> void

View File

@ -5,6 +5,7 @@ require "securerandom"
module Zeitwerk::Loader::Config
extend Zeitwerk::Internal
include Zeitwerk::RealModName
# @sig #camelize
attr_accessor :inflector
@ -12,14 +13,15 @@ module Zeitwerk::Loader::Config
# @sig #call | #debug | nil
attr_accessor :logger
# Absolute paths of the root directories. Stored in a hash to preserve order,
# easily handle duplicates, have a fast lookup needed for detecting nested
# paths, and store namespaces as values.
# Absolute paths of the root directories, mapped to their respective root namespaces:
#
# "/Users/fxn/blog/app/channels" => Object,
# "/Users/fxn/blog/app/adapters" => ActiveJob::QueueAdapters,
# ...
#
# Stored in a hash to preserve order, easily handle duplicates, and have a
# fast lookup by directory.
#
# This is a private collection maintained by the loader. The public
# interface for it is `push_dir` and `dirs`.
#
@ -112,6 +114,10 @@ module Zeitwerk::Loader::Config
raise Zeitwerk::Error, "#{namespace.inspect} is not a class or module object, should be"
end
unless real_mod_name(namespace)
raise Zeitwerk::Error, "root namespaces cannot be anonymous"
end
abspath = File.expand_path(path)
if dir?(abspath)
raise_if_conflicting_directory(abspath)
@ -283,17 +289,22 @@ module Zeitwerk::Loader::Config
return false if ignored_paths.empty?
walk_up(abspath) do |abspath|
return true if ignored_paths.member?(abspath)
return true if ignored_path?(abspath)
return false if roots.key?(abspath)
end
false
end
# @sig (String) -> bool
private def ignored_path?(abspath)
ignored_paths.member?(abspath)
end
# @sig () -> Array[String]
private def actual_roots
roots.reject do |root_dir, _root_namespace|
!dir?(root_dir) || ignored_paths.member?(root_dir)
!dir?(root_dir) || ignored_path?(root_dir)
end
end

View File

@ -9,6 +9,7 @@ module Zeitwerk::Loader::EagerLoad
def eager_load(force: false)
mutex.synchronize do
break if @eager_loaded
raise Zeitwerk::SetupRequired unless @setup
log("eager load start") if logger
@ -29,6 +30,8 @@ module Zeitwerk::Loader::EagerLoad
# @sig (String | Pathname) -> void
def eager_load_dir(path)
raise Zeitwerk::SetupRequired unless @setup
abspath = File.expand_path(path)
raise Zeitwerk::Error.new("#{abspath} is not a directory") unless dir?(abspath)
@ -37,7 +40,7 @@ module Zeitwerk::Loader::EagerLoad
root_namespace = nil
walk_up(abspath) do |dir|
return if ignored_paths.member?(dir)
return if ignored_path?(dir)
return if eager_load_exclusions.member?(dir)
break if root_namespace = roots[dir]
@ -67,6 +70,8 @@ module Zeitwerk::Loader::EagerLoad
# @sig (Module) -> void
def eager_load_namespace(mod)
raise Zeitwerk::SetupRequired unless @setup
unless mod.is_a?(Module)
raise Zeitwerk::Error, "#{mod.inspect} is not a class or module object"
end
@ -111,7 +116,7 @@ module Zeitwerk::Loader::EagerLoad
raise Zeitwerk::Error.new("#{abspath} does not exist") unless File.exist?(abspath)
raise Zeitwerk::Error.new("#{abspath} is not a Ruby file") if dir?(abspath) || !ruby?(abspath)
raise Zeitwerk::Error.new("#{abspath} is ignored") if ignored_paths.member?(abspath)
raise Zeitwerk::Error.new("#{abspath} is ignored") if ignored_path?(abspath)
basename = File.basename(abspath, ".rb")
base_cname = inflector.camelize(basename, abspath).to_sym
@ -120,7 +125,7 @@ module Zeitwerk::Loader::EagerLoad
cnames = []
walk_up(File.dirname(abspath)) do |dir|
raise Zeitwerk::Error.new("#{abspath} is ignored") if ignored_paths.member?(dir)
raise Zeitwerk::Error.new("#{abspath} is ignored") if ignored_path?(dir)
break if root_namespace = roots[dir]
@ -203,7 +208,7 @@ module Zeitwerk::Loader::EagerLoad
next unless dir?(abspath)
if collapse?(abspath)
current_dirs << abspath
dirs << abspath
elsif segment == inflector.camelize(basename, abspath)
next_dirs << abspath
end

View File

@ -1,12 +1,10 @@
# frozen_string_literal: true
module Zeitwerk::Loader::Helpers
private
# --- Logging -----------------------------------------------------------------------------------
# @sig (String) -> void
def log(message)
private def log(message)
method_name = logger.respond_to?(:debug) ? :debug : :call
logger.send(method_name, "Zeitwerk@#{tag}: #{message}")
end
@ -14,7 +12,7 @@ module Zeitwerk::Loader::Helpers
# --- Files and directories ---------------------------------------------------------------------
# @sig (String) { (String, String) -> void } -> void
def ls(dir)
private def ls(dir)
children = Dir.children(dir)
# The order in which a directory is listed depends on the file system.
@ -28,7 +26,7 @@ module Zeitwerk::Loader::Helpers
next if hidden?(basename)
abspath = File.join(dir, basename)
next if ignored_paths.member?(abspath)
next if ignored_path?(abspath)
if dir?(abspath)
next if roots.key?(abspath)
@ -44,7 +42,7 @@ module Zeitwerk::Loader::Helpers
end
# @sig (String) -> bool
def has_at_least_one_ruby_file?(dir)
private def has_at_least_one_ruby_file?(dir)
to_visit = [dir]
while dir = to_visit.shift
@ -61,22 +59,22 @@ module Zeitwerk::Loader::Helpers
end
# @sig (String) -> bool
def ruby?(path)
private def ruby?(path)
path.end_with?(".rb")
end
# @sig (String) -> bool
def dir?(path)
private def dir?(path)
File.directory?(path)
end
# @sig (String) -> bool
def hidden?(basename)
private def hidden?(basename)
basename.start_with?(".")
end
# @sig (String) { (String) -> void } -> void
def walk_up(abspath)
private def walk_up(abspath)
loop do
yield abspath
abspath, basename = File.split(abspath)
@ -104,11 +102,11 @@ module Zeitwerk::Loader::Helpers
#
# @sig (Module, Symbol) -> String?
if method(:autoload?).arity == 1
def strict_autoload_path(parent, cname)
private def strict_autoload_path(parent, cname)
parent.autoload?(cname) if cdef?(parent, cname)
end
else
def strict_autoload_path(parent, cname)
private def strict_autoload_path(parent, cname)
parent.autoload?(cname, false)
end
end
@ -117,23 +115,23 @@ module Zeitwerk::Loader::Helpers
if Symbol.method_defined?(:name)
# Symbol#name was introduced in Ruby 3.0. It returns always the same
# frozen object, so we may save a few string allocations.
def cpath(parent, cname)
private def cpath(parent, cname)
Object == parent ? cname.name : "#{real_mod_name(parent)}::#{cname.name}"
end
else
def cpath(parent, cname)
private def cpath(parent, cname)
Object == parent ? cname.to_s : "#{real_mod_name(parent)}::#{cname}"
end
end
# @sig (Module, Symbol) -> bool
def cdef?(parent, cname)
private def cdef?(parent, cname)
parent.const_defined?(cname, false)
end
# @raise [NameError]
# @sig (Module, Symbol) -> Object
def cget(parent, cname)
private def cget(parent, cname)
parent.const_get(cname, false)
end
end

View File

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