brew vendor-gems: commit updates.
This commit is contained in:
parent
9619682035
commit
85e5e3708e
@ -7,7 +7,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/concurrent-ruby-1.1.1
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.10.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.10.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.15.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.15.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tzinfo-2.0.4/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tzinfo-2.0.4/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/zeitwerk-2.5.4/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/zeitwerk-2.6.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/activesupport-6.1.6/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/activesupport-6.1.6/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/public_suffix-4.0.7/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/public_suffix-4.0.7/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/addressable-2.8.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/addressable-2.8.0/lib"
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
module Zeitwerk
|
module Zeitwerk
|
||||||
require_relative "zeitwerk/real_mod_name"
|
require_relative "zeitwerk/real_mod_name"
|
||||||
require_relative "zeitwerk/loader"
|
require_relative "zeitwerk/loader"
|
||||||
|
require_relative "zeitwerk/gem_loader"
|
||||||
require_relative "zeitwerk/registry"
|
require_relative "zeitwerk/registry"
|
||||||
require_relative "zeitwerk/explicit_namespace"
|
require_relative "zeitwerk/explicit_namespace"
|
||||||
require_relative "zeitwerk/inflector"
|
require_relative "zeitwerk/inflector"
|
||||||
@ -5,6 +5,9 @@ module Zeitwerk
|
|||||||
end
|
end
|
||||||
|
|
||||||
class ReloadingDisabledError < Error
|
class ReloadingDisabledError < Error
|
||||||
|
def initialize
|
||||||
|
super("can't reload, please call loader.enable_reloading before setup")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NameError < ::NameError
|
class NameError < ::NameError
|
||||||
65
Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.6.0/lib/zeitwerk/gem_loader.rb
vendored
Normal file
65
Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.6.0/lib/zeitwerk/gem_loader.rb
vendored
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Zeitwerk
|
||||||
|
# @private
|
||||||
|
class GemLoader < Loader
|
||||||
|
# Users should not create instances directly, the public interface is
|
||||||
|
# `Zeitwerk::Loader.for_gem`.
|
||||||
|
private_class_method :new
|
||||||
|
|
||||||
|
# @private
|
||||||
|
# @sig (String, bool) -> Zeitwerk::GemLoader
|
||||||
|
def self._new(root_file, warn_on_extra_files:)
|
||||||
|
new(root_file, warn_on_extra_files: warn_on_extra_files)
|
||||||
|
end
|
||||||
|
|
||||||
|
# @sig (String, bool) -> void
|
||||||
|
def initialize(root_file, warn_on_extra_files:)
|
||||||
|
super()
|
||||||
|
|
||||||
|
@tag = File.basename(root_file, ".rb")
|
||||||
|
@inflector = GemInflector.new(root_file)
|
||||||
|
@root_file = File.expand_path(root_file)
|
||||||
|
@lib = File.dirname(root_file)
|
||||||
|
@warn_on_extra_files = warn_on_extra_files
|
||||||
|
|
||||||
|
push_dir(@lib)
|
||||||
|
end
|
||||||
|
|
||||||
|
# @sig () -> void
|
||||||
|
def setup
|
||||||
|
warn_on_extra_files if @warn_on_extra_files
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# @sig () -> void
|
||||||
|
def warn_on_extra_files
|
||||||
|
expected_namespace_dir = @root_file.delete_suffix(".rb")
|
||||||
|
|
||||||
|
ls(@lib) do |basename, abspath|
|
||||||
|
next if abspath == @root_file
|
||||||
|
next if abspath == expected_namespace_dir
|
||||||
|
|
||||||
|
basename_without_ext = basename.delete_suffix(".rb")
|
||||||
|
cname = inflector.camelize(basename_without_ext, abspath)
|
||||||
|
ftype = dir?(abspath) ? "directory" : "file"
|
||||||
|
|
||||||
|
warn(<<~EOS)
|
||||||
|
WARNING: Zeitwerk defines the constant #{cname} after the #{ftype}
|
||||||
|
|
||||||
|
#{abspath}
|
||||||
|
|
||||||
|
To prevent that, please configure the loader to ignore it:
|
||||||
|
|
||||||
|
loader.ignore("\#{__dir__}/#{basename}")
|
||||||
|
|
||||||
|
Otherwise, there is a flag to silence this warning:
|
||||||
|
|
||||||
|
Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -13,6 +13,9 @@ module Zeitwerk
|
|||||||
include Helpers
|
include Helpers
|
||||||
include Config
|
include Config
|
||||||
|
|
||||||
|
MUTEX = Mutex.new
|
||||||
|
private_constant :MUTEX
|
||||||
|
|
||||||
# Maps absolute paths for which an autoload has been set ---and not
|
# Maps absolute paths for which an autoload has been set ---and not
|
||||||
# executed--- to their corresponding parent class or module and constant
|
# executed--- to their corresponding parent class or module and constant
|
||||||
# name.
|
# name.
|
||||||
@ -144,15 +147,16 @@ module Zeitwerk
|
|||||||
end
|
end
|
||||||
|
|
||||||
to_unload.each do |cpath, (abspath, (parent, cname))|
|
to_unload.each do |cpath, (abspath, (parent, cname))|
|
||||||
# We have to check cdef? in this condition. Reason is, constants whose
|
unless on_unload_callbacks.empty?
|
||||||
# file does not define them have to be kept in to_unload as explained
|
begin
|
||||||
# in the implementation of on_file_autoloaded.
|
value = cget(parent, cname)
|
||||||
#
|
rescue ::NameError
|
||||||
# If the constant is not defined, on_unload should not be triggered
|
# Perhaps the user deleted the constant by hand, or perhaps an
|
||||||
# for it.
|
# autoload failed to define the expected constant but the user
|
||||||
if !on_unload_callbacks.empty? && cdef?(parent, cname)
|
# rescued the exception.
|
||||||
value = parent.const_get(cname)
|
else
|
||||||
run_on_unload_callbacks(cpath, value, abspath)
|
run_on_unload_callbacks(cpath, value, abspath)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unload_cref(parent, cname)
|
unload_cref(parent, cname)
|
||||||
@ -196,14 +200,12 @@ module Zeitwerk
|
|||||||
# @raise [Zeitwerk::Error]
|
# @raise [Zeitwerk::Error]
|
||||||
# @sig () -> void
|
# @sig () -> void
|
||||||
def reload
|
def reload
|
||||||
if reloading_enabled?
|
raise ReloadingDisabledError unless reloading_enabled?
|
||||||
unload
|
|
||||||
recompute_ignored_paths
|
unload
|
||||||
recompute_collapse_dirs
|
recompute_ignored_paths
|
||||||
setup
|
recompute_collapse_dirs
|
||||||
else
|
setup
|
||||||
raise ReloadingDisabledError, "can't reload, please call loader.enable_reloading before setup"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Eager loads all files in the root directories, recursively. Files do not
|
# Eager loads all files in the root directories, recursively. Files do not
|
||||||
@ -236,7 +238,7 @@ module Zeitwerk
|
|||||||
if cref = autoloads[abspath]
|
if cref = autoloads[abspath]
|
||||||
cget(*cref)
|
cget(*cref)
|
||||||
end
|
end
|
||||||
elsif dir?(abspath) && !root_dirs.key?(abspath)
|
elsif !root_dirs.key?(abspath)
|
||||||
if collapse?(abspath)
|
if collapse?(abspath)
|
||||||
queue << [namespace, abspath]
|
queue << [namespace, abspath]
|
||||||
else
|
else
|
||||||
@ -289,10 +291,6 @@ module Zeitwerk
|
|||||||
# @sig #call | #debug | nil
|
# @sig #call | #debug | nil
|
||||||
attr_accessor :default_logger
|
attr_accessor :default_logger
|
||||||
|
|
||||||
# @private
|
|
||||||
# @sig Mutex
|
|
||||||
attr_accessor :mutex
|
|
||||||
|
|
||||||
# This is a shortcut for
|
# This is a shortcut for
|
||||||
#
|
#
|
||||||
# require "zeitwerk"
|
# require "zeitwerk"
|
||||||
@ -304,10 +302,13 @@ module Zeitwerk
|
|||||||
# except that this method returns the same object in subsequent calls from
|
# except that this method returns the same object in subsequent calls from
|
||||||
# the same file, in the unlikely case the gem wants to be able to reload.
|
# the same file, in the unlikely case the gem wants to be able to reload.
|
||||||
#
|
#
|
||||||
# @sig () -> Zeitwerk::Loader
|
# This method returns a subclass of Zeitwerk::Loader, but the exact type
|
||||||
def for_gem
|
# is private, client code can only rely on the interface.
|
||||||
|
#
|
||||||
|
# @sig (bool) -> Zeitwerk::GemLoader
|
||||||
|
def for_gem(warn_on_extra_files: true)
|
||||||
called_from = caller_locations(1, 1).first.path
|
called_from = caller_locations(1, 1).first.path
|
||||||
Registry.loader_for_gem(called_from)
|
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.
|
||||||
@ -326,8 +327,6 @@ module Zeitwerk
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.mutex = Mutex.new
|
|
||||||
|
|
||||||
private # -------------------------------------------------------------------------------------
|
private # -------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# @sig (String, Module) -> void
|
# @sig (String, Module) -> void
|
||||||
@ -338,7 +337,7 @@ module Zeitwerk
|
|||||||
basename.delete_suffix!(".rb")
|
basename.delete_suffix!(".rb")
|
||||||
cname = inflector.camelize(basename, abspath).to_sym
|
cname = inflector.camelize(basename, abspath).to_sym
|
||||||
autoload_file(parent, cname, abspath)
|
autoload_file(parent, cname, abspath)
|
||||||
elsif dir?(abspath)
|
else
|
||||||
# In a Rails application, `app/models/concerns` is a subdirectory of
|
# In a Rails application, `app/models/concerns` is a subdirectory of
|
||||||
# `app/models`, but both of them are root directories.
|
# `app/models`, but both of them are root directories.
|
||||||
#
|
#
|
||||||
@ -466,7 +465,7 @@ module Zeitwerk
|
|||||||
|
|
||||||
# @sig (String) -> void
|
# @sig (String) -> void
|
||||||
def raise_if_conflicting_directory(dir)
|
def raise_if_conflicting_directory(dir)
|
||||||
self.class.mutex.synchronize do
|
MUTEX.synchronize do
|
||||||
Registry.loaders.each do |loader|
|
Registry.loaders.each do |loader|
|
||||||
next if loader == self
|
next if loader == self
|
||||||
next if loader.ignores?(dir)
|
next if loader.ignores?(dir)
|
||||||
@ -131,7 +131,6 @@ module Zeitwerk::Loader::Config
|
|||||||
|
|
||||||
# Sets a tag for the loader, useful for logging.
|
# Sets a tag for the loader, useful for logging.
|
||||||
#
|
#
|
||||||
# @param tag [#to_s]
|
|
||||||
# @sig (#to_s) -> void
|
# @sig (#to_s) -> void
|
||||||
def tag=(tag)
|
def tag=(tag)
|
||||||
@tag = tag.to_s
|
@tag = tag.to_s
|
||||||
@ -15,18 +15,50 @@ module Zeitwerk::Loader::Helpers
|
|||||||
|
|
||||||
# @sig (String) { (String, String) -> void } -> void
|
# @sig (String) { (String, String) -> void } -> void
|
||||||
def ls(dir)
|
def ls(dir)
|
||||||
Dir.each_child(dir) do |basename|
|
children = Dir.children(dir)
|
||||||
|
|
||||||
|
# The order in which a directory is listed depends on the file system.
|
||||||
|
#
|
||||||
|
# Since client code may run in different platforms, it seems convenient to
|
||||||
|
# order directory entries. This provides consistent eager loading across
|
||||||
|
# platforms, for example.
|
||||||
|
children.sort!
|
||||||
|
|
||||||
|
children.each do |basename|
|
||||||
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_paths.member?(abspath)
|
||||||
|
|
||||||
|
if dir?(abspath)
|
||||||
|
next unless has_at_least_one_ruby_file?(abspath)
|
||||||
|
else
|
||||||
|
next unless ruby?(abspath)
|
||||||
|
end
|
||||||
|
|
||||||
# We freeze abspath because that saves allocations when passed later to
|
# We freeze abspath because that saves allocations when passed later to
|
||||||
# File methods. See #125.
|
# File methods. See #125.
|
||||||
yield basename, abspath.freeze
|
yield basename, abspath.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @sig (String) -> bool
|
||||||
|
def has_at_least_one_ruby_file?(dir)
|
||||||
|
to_visit = [dir]
|
||||||
|
|
||||||
|
while dir = to_visit.shift
|
||||||
|
ls(dir) do |_basename, abspath|
|
||||||
|
if dir?(abspath)
|
||||||
|
to_visit << abspath
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
# @sig (String) -> bool
|
# @sig (String) -> bool
|
||||||
def ruby?(path)
|
def ruby?(path)
|
||||||
path.end_with?(".rb")
|
path.end_with?(".rb")
|
||||||
@ -37,7 +69,7 @@ module Zeitwerk::Loader::Helpers
|
|||||||
File.directory?(path)
|
File.directory?(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @sig String -> bool
|
# @sig (String) -> bool
|
||||||
def hidden?(basename)
|
def hidden?(basename)
|
||||||
basename.start_with?(".")
|
basename.start_with?(".")
|
||||||
end
|
end
|
||||||
@ -10,12 +10,11 @@ module Zeitwerk
|
|||||||
# @sig Array[Zeitwerk::Loader]
|
# @sig Array[Zeitwerk::Loader]
|
||||||
attr_reader :loaders
|
attr_reader :loaders
|
||||||
|
|
||||||
# Registers loaders created with `for_gem` to make the method idempotent
|
# Registers gem loaders to let `for_gem` be idempotent in case of reload.
|
||||||
# in case of reload.
|
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
# @sig Hash[String, Zeitwerk::Loader]
|
# @sig Hash[String, Zeitwerk::Loader]
|
||||||
attr_reader :loaders_managing_gems
|
attr_reader :gem_loaders_by_root_file
|
||||||
|
|
||||||
# Maps absolute paths to the loaders responsible for them.
|
# Maps absolute paths to the loaders responsible for them.
|
||||||
#
|
#
|
||||||
@ -77,7 +76,7 @@ module Zeitwerk
|
|||||||
# @sig (Zeitwerk::Loader) -> void
|
# @sig (Zeitwerk::Loader) -> void
|
||||||
def unregister_loader(loader)
|
def unregister_loader(loader)
|
||||||
loaders.delete(loader)
|
loaders.delete(loader)
|
||||||
loaders_managing_gems.delete_if { |_, l| l == loader }
|
gem_loaders_by_root_file.delete_if { |_, l| l == loader }
|
||||||
autoloads.delete_if { |_, l| l == loader }
|
autoloads.delete_if { |_, l| l == loader }
|
||||||
inceptions.delete_if { |_, (_, l)| l == loader }
|
inceptions.delete_if { |_, (_, l)| l == loader }
|
||||||
end
|
end
|
||||||
@ -87,14 +86,8 @@ module Zeitwerk
|
|||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
# @sig (String) -> Zeitwerk::Loader
|
# @sig (String) -> Zeitwerk::Loader
|
||||||
def loader_for_gem(root_file)
|
def loader_for_gem(root_file, warn_on_extra_files:)
|
||||||
loaders_managing_gems[root_file] ||= begin
|
gem_loaders_by_root_file[root_file] ||= GemLoader._new(root_file, warn_on_extra_files: warn_on_extra_files)
|
||||||
Loader.new.tap do |loader|
|
|
||||||
loader.tag = File.basename(root_file, ".rb")
|
|
||||||
loader.inflector = GemInflector.new(root_file)
|
|
||||||
loader.push_dir(File.dirname(root_file))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
@ -137,9 +130,9 @@ module Zeitwerk
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@loaders = []
|
@loaders = []
|
||||||
@loaders_managing_gems = {}
|
@gem_loaders_by_root_file = {}
|
||||||
@autoloads = {}
|
@autoloads = {}
|
||||||
@inceptions = {}
|
@inceptions = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Zeitwerk
|
module Zeitwerk
|
||||||
VERSION = "2.5.4"
|
VERSION = "2.6.0"
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user