From bfc9065d58508fb19dd1a4170406604dd3b3234a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 28 Jul 2019 13:49:26 +0200 Subject: Improves compatibility of require_dependency in zeitwerk mode [Closes #36774] Applications are not supposed to use require_dependency in their own code if running in zeitwerk mode, and require_dependency was initially aliased to require with that use case in mind. However, there are situations in which you cannot control the mode and need to be compatible with both. There, you might need require_dependency in case you are being executed in classic mode. Think about engines that want to support both modes in their parent applications, for example. Furthermore, Rails itself loads helpers using require_dependency. Therefore, we need better compatibility. --- .../lib/active_support/dependencies/zeitwerk_integration.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb index f75083a05a..2cf55713bd 100644 --- a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb +++ b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb @@ -42,6 +42,17 @@ module ActiveSupport end end + module RequireDependency + def require_dependency(filename) + filename = filename.to_path if filename.respond_to?(:to_path) + if abspath = ActiveSupport::Dependencies.search_for_file(filename) + require abspath + else + require filename + end + end + end + module Inflector def self.camelize(basename, _abspath) basename.camelize @@ -90,7 +101,7 @@ module ActiveSupport def decorate_dependencies Dependencies.unhook! Dependencies.singleton_class.prepend(Decorations) - Object.class_eval { alias_method :require_dependency, :require } + Object.prepend(RequireDependency) end end end -- cgit v1.2.3