aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/dependencies.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/dependencies.rb')
-rw-r--r--activesupport/lib/active_support/dependencies.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 56de29b730..9c4412c28c 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -76,17 +76,19 @@ module ActiveSupport #:nodoc:
locked :concat, :each, :delete_if, :<<
def new_constants_for(frames)
- frames.map do |mod_name, prior_constants|
- mod = Inflector.constantize(mod_name)
+ constants = []
+ frames.each do |mod_name, prior_constants|
+ mod = Inflector.constantize(mod_name) if Dependencies.qualified_const_defined?(mod_name)
next unless mod.is_a?(Module)
new_constants = mod.local_constant_names - prior_constants
get(mod_name).concat(new_constants)
- new_constants.map do |suffix|
- ([mod_name, suffix] - ["Object"]).join("::")
+ new_constants.each do |suffix|
+ constants << ([mod_name, suffix] - ["Object"]).join("::")
end
- end.flatten
+ end
+ constants
end
# Add a set of modules to the watch stack, remembering the initial constants
@@ -115,8 +117,8 @@ module ActiveSupport #:nodoc:
def self.append_features(base)
base.class_eval do
# Emulate #exclude via an ivar
- return if @_const_missing
- @_const_missing = method(:const_missing)
+ return if defined?(@_const_missing) && @_const_missing
+ @_const_missing = instance_method(:const_missing)
remove_method(:const_missing)
end
super
@@ -177,6 +179,10 @@ module ActiveSupport #:nodoc:
end
def require_dependency(file_name, message = "No such file to load -- %s")
+ unless file_name.is_a?(String)
+ raise ArgumentError, "the file name must be a String -- you passed #{file_name.inspect}"
+ end
+
Dependencies.depend_on(file_name, false, message)
end
@@ -435,7 +441,10 @@ module ActiveSupport #:nodoc:
qualified_name = qualified_name_for from_mod, const_name
path_suffix = qualified_name.underscore
+
+ trace = caller.reject {|l| l =~ %r{#{Regexp.escape(__FILE__)}}}
name_error = NameError.new("uninitialized constant #{qualified_name}")
+ name_error.set_backtrace(trace)
file_path = search_for_file(path_suffix)