Created
April 8, 2011 17:50
-
-
Save cowboycoded/910364 to your computer and use it in GitHub Desktop.
dependency methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#activesupport-3.0.5/lib/active_support/dependencies.rb | |
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 | |
def depend_on(file_name, swallow_load_errors = false, message = "No such file to load -- %s.rb") | |
path = search_for_file(file_name) | |
require_or_load(path || file_name) | |
rescue LoadError => load_error | |
unless swallow_load_errors | |
if file_name = load_error.message[/ -- (.*?)(\.rb)?$/, 1] | |
raise LoadError.new(message % file_name).copy_blame!(load_error) | |
end | |
raise | |
end | |
end | |
def search_for_file(path_suffix) | |
path_suffix = path_suffix.sub(/(\.rb)?$/, ".rb") | |
autoload_paths.each do |root| | |
path = File.join(root, path_suffix) | |
return path if File.file? path | |
end | |
nil # Gee, I sure wish we had first_match | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment