Permalink
Browse files

Updated dependency loading to consider non-standard class/file name c…

…ombinations

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@712 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 5fa66cd commit beb2875094d8038b1d5d8fc1a5943884cf96ccf4 @dhh dhh committed Feb 20, 2005
Showing with 22 additions and 5 deletions.
  1. +21 −4 activesupport/lib/active_support/dependencies.rb
  2. +1 −1 railties/lib/dispatcher.rb
@@ -16,6 +16,7 @@ def load?
def depend_on(file_name, swallow_load_errors = false)
if !loaded.include?(file_name)
loaded << file_name
+
begin
require_or_load(file_name)
rescue LoadError
@@ -69,11 +70,13 @@ def const_missing(name)
end
# Load the controller class or a parent module.
- def const_load!(name)
- path = self.path + [name]
+ def const_load!(name, file_name = nil)
+ path = self.path + [file_name || name]
+
load_paths.each do |load_path|
fs_path = load_path.filesystem_path(path)
next unless fs_path
+
if File.directory?(fs_path)
self.const_set name, LoadingModule.new(self.root, self.path + [name])
break
@@ -82,6 +85,7 @@ def const_load!(name)
break
end
end
+
return self.const_defined?(name)
end
@@ -94,16 +98,20 @@ def const_available?(name)
class RootLoadingModule < LoadingModule
attr_reader :load_paths
+
def initialize(*paths)
@load_paths = paths.flatten.collect {|p| p.kind_of?(ConstantLoadPath) ? p : ConstantLoadPath.new(p)}
end
+
def root() self end
+
def path() [] end
# Load the source file at the given file path
def load_file!(file_path)
root.module_eval(IO.read(file_path), file_path, 1)
end
+
# Erase all items in this module
def clear!
constants.each do |name|
@@ -123,17 +131,21 @@ def initialize(root) @root = root end
def filesystem_path(path, allow_module=true)
fs_path = [@root]
fs_path += path[0..-2].collect {|name| const_name_to_module_name name}
+
if allow_module
result = File.join(fs_path, const_name_to_module_name(path.last))
return result if File.directory? result # Return the module path if one exists
- end
+ end
+
result = File.join(fs_path, const_name_to_file_name(path.last))
+
return File.file?(result) ? result : nil
end
def const_name_to_file_name(name)
name.to_s.underscore + '.rb'
end
+
def const_name_to_module_name(name)
name.to_s.underscore
end
@@ -152,6 +164,7 @@ def const_missing(class_id)
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)
if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end
@@ -160,13 +173,15 @@ def const_missing(class_id)
end
end
end
+
def load(file, *extras)
begin super(file, *extras)
rescue Object => exception
exception.blame_file! file
raise
end
end
+
def require(file, *extras)
begin super(file, *extras)
rescue Object => exception
@@ -181,9 +196,11 @@ class Exception
def blame_file!(file)
(@blamed_files ||= []).unshift file
end
+
attr_reader :blamed_files
+
def describe_blame
return nil if blamed_files.empty?
"This error occured while loading the following files:\n #{blamed_files.join '\n '}"
end
-end
+end
@@ -41,7 +41,7 @@ def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFA
def prepare_application
ActionController::Routing::Routes.reload if Dependencies.load?
Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)
- Controllers.const_load!("application") unless Controllers.const_defined?(:ApplicationController)
+ Controllers.const_load!(:ApplicationController, "application") unless Controllers.const_defined?(:ApplicationController)
end
def reset_application

0 comments on commit beb2875

Please sign in to comment.