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/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/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/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/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/public_suffix-5.0.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/addressable-2.8.1/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 class NameError < ::NameError
end end
class SetupRequired < Error
def initialize
super("please, finish your configuration and call Zeitwerk::Loader#setup once all is ready")
end
end
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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