lib/active_support/dependencies.rb in activesupport-1.0.3 vs lib/active_support/dependencies.rb in activesupport-1.0.4
- old
+ new
@@ -53,11 +53,11 @@
attr_reader :root
def self.root(*load_paths)
RootLoadingModule.new(*load_paths)
end
-
+
def initialize(root, path=[])
@path = path.clone.freeze
@root = root
end
@@ -79,24 +79,26 @@
if File.directory?(fs_path)
new_module = LoadingModule.new(self.root, self.path + [name])
self.const_set name, new_module
if self.root?
- raise NameError, "Cannot load controller module named #{name}: An object of type #{Object.const_get(name).class.to_s} already exists." \
- if Object.const_defined?(name)
- Object.const_set(name, new_module)
+ if Object.const_defined?(name)
+ msg = "Cannot load module #{name}: Object::#{name} is set to #{Object.const_get(name).inspect}"
+ raise NameError, msg
+ end
+ Object.const_set(name, new_module)
end
break
elsif File.file?(fs_path)
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)
break
end
end
-
+
return self.const_defined?(name)
end
# Is this name present or loadable?
# This method is used by Routes to find valid controllers.
@@ -122,11 +124,11 @@
end
# Erase all items in this module
def clear!
constants.each do |name|
- Object.send(:remove_const, name) if Object.const_defined?(name)
+ Object.send(:remove_const, name) if Object.const_defined?(name) && Object.const_get(name).object_id == self.const_get(name).object_id
self.send(:remove_const, name)
end
end
end
@@ -173,10 +175,10 @@
if Object.const_defined?(:Controllers) and Object::Controllers.const_available?(class_id)
return Object::Controllers.const_get(class_id)
end
begin
- require_or_load(class_id.to_s.demodulize.underscore)
+ 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)
end
end