Skip to content

Commit

Permalink
Merge pull request #43073 from rails/autoloaded-p
Browse files Browse the repository at this point in the history
Delete AS::Dependencies.autoloaded?
  • Loading branch information
fxn committed Aug 23, 2021
2 parents 39a7658 + b99b14a commit 9615e21
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 77 deletions.
33 changes: 0 additions & 33 deletions activesupport/lib/active_support/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ def eager_load?(path)
def clear
end

# Is the provided constant path defined?
def qualified_const_defined?(path)
Object.const_defined?(path, false)
end

# Search for a file in autoload_paths matching the provided suffix.
def search_for_file(path_suffix)
path_suffix += ".rb" unless path_suffix.end_with?(".rb")
Expand All @@ -85,33 +80,5 @@ def search_for_file(path_suffix)
end
nil # Gee, I sure wish we had first_match ;-)
end

# Determine if the given constant has been automatically loaded.
def autoloaded?(desc)
return false if desc.is_a?(Module) && real_mod_name(desc).nil?
name = to_constant_name desc
return false unless qualified_const_defined?(name)
autoloaded_constants.include?(name)
end

# Convert the provided const desc to a qualified constant name (as a string).
# A module, class, symbol, or string may be provided.
def to_constant_name(desc) # :nodoc:
case desc
when String then desc.delete_prefix("::")
when Symbol then desc.to_s
when Module
real_mod_name(desc) ||
raise(ArgumentError, "Anonymous modules have no name to be referenced by")
else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}"
end
end

private
# Returns the original name of a class or module even if `name` has been
# overridden.
def real_mod_name(mod)
UNBOUND_METHOD_MODULE_NAME.bind_call(mod)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ def autoloaded_constants
Rails.autoloaders.main.unloadable_cpaths
end

def autoloaded?(object)
cpath = object.is_a?(Module) ? real_mod_name(object) : object.to_s
Rails.autoloaders.main.unloadable_cpath?(cpath)
end

def verbose=(verbose)
l = verbose ? logger || Rails.logger : nil
Rails.autoloaders.each { |autoloader| autoloader.logger = l }
Expand Down
19 changes: 0 additions & 19 deletions activesupport/test/dependencies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,6 @@ def test_smart_name_error_strings
end
assert_includes "uninitialized constant ImaginaryObject", e.message
end

def test_qualified_const_defined
assert ActiveSupport::Dependencies.qualified_const_defined?("Object")
assert ActiveSupport::Dependencies.qualified_const_defined?("::Object")
assert ActiveSupport::Dependencies.qualified_const_defined?("::Object::Kernel")
assert ActiveSupport::Dependencies.qualified_const_defined?("::ActiveSupport::TestCase")
end

def test_qualified_const_defined_should_not_call_const_missing
ModuleWithMissing.missing_count = 0
assert_not ActiveSupport::Dependencies.qualified_const_defined?("ModuleWithMissing::A")
assert_equal 0, ModuleWithMissing.missing_count
assert_not ActiveSupport::Dependencies.qualified_const_defined?("ModuleWithMissing::A::B")
assert_equal 0, ModuleWithMissing.missing_count
end

def test_qualified_const_defined_explodes_with_invalid_const_name
assert_raises(NameError) { ActiveSupport::Dependencies.qualified_const_defined?("invalid") }
end
end

class RequireDependencyTest < ActiveSupport::TestCase
Expand Down
20 changes: 0 additions & 20 deletions railties/test/application/zeitwerk_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ class RESTfulController < ApplicationController
assert RESTfulController
end

test "autoloaded? and overridden class names" do
invalid_constant_name = Module.new do
def self.name
"MyModule::SchemaMigration"
end
end
assert_not deps.autoloaded?(invalid_constant_name)
end

test "the once autoloader can autoload from initializers" do
app_file "extras0/x.rb", "X = 0"
Expand Down Expand Up @@ -126,10 +118,6 @@ def self.name

assert Post

assert deps.autoloaded?("Post")
assert deps.autoloaded?(Post)
assert_not deps.autoloaded?("User")

assert_equal ["Post"], deps.autoloaded_constants
end

Expand All @@ -141,10 +129,6 @@ def self.name

assert Foo

assert_not deps.autoloaded?("Foo")
assert_not deps.autoloaded?(Foo)
assert_not deps.autoloaded?("Bar")

assert_empty deps.autoloaded_constants
end

Expand All @@ -155,10 +139,6 @@ def self.name

assert Post

assert_not deps.autoloaded?("Post")
assert_not deps.autoloaded?(Post)
assert_not deps.autoloaded?("User")

assert_empty deps.autoloaded_constants
end

Expand Down

0 comments on commit 9615e21

Please sign in to comment.