lib/active_support/dependencies.rb in activesupport-1.1.1 vs lib/active_support/dependencies.rb in activesupport-1.2.1
- old
+ new
@@ -91,14 +91,20 @@
end
Object.const_set(name, new_module)
end
break
when File.file?(fs_path)
- self.root.load_file!(fs_path)
+ loaded_file = self.root.load_file!(fs_path)
# Import the loaded constant from Object provided we are the root node.
self.const_set(name, Object.const_get(name)) if self.root? && Object.const_defined?(name)
+
+ # Throw an error if we load the file but we don't find the Object we expect
+ if loaded_file and not self.const_defined?(name)
+ msg = "Already loaded file '#{fs_path}' but '#{name.to_s}' was not set, perhaps you need to rename '#{fs_path}'?"
+ raise LoadError, msg
+ end
break
end
end
self.const_defined?(name)
@@ -170,10 +176,13 @@
Object.send(:define_method, :require_or_load) { |file_name| Dependencies.require_or_load(file_name) } unless Object.respond_to?(:require_or_load)
Object.send(:define_method, :require_dependency) { |file_name| Dependencies.depend_on(file_name) } unless Object.respond_to?(:require_dependency)
Object.send(:define_method, :require_association) { |file_name| Dependencies.associate_with(file_name) } unless Object.respond_to?(:require_association)
class Module #:nodoc:
+ # Rename the original handler so we can chain it to the new one
+ alias :rails_original_const_missing :const_missing
+
# Use const_missing to autoload associations so we don't have to
# require_association when using single-table inheritance.
def const_missing(class_id)
if Object.const_defined?(:Controllers) and Object::Controllers.const_available?(class_id)
return Object::Controllers.const_get(class_id)
@@ -181,10 +190,14 @@
begin
require_dependency(class_id.to_s.demodulize.underscore)
if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end
rescue LoadError => e
- raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)
+ begin
+ rails_original_const_missing(class_id)
+ rescue Exception
+ raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)
+ end
end
end
end
class Object #:nodoc: