Skip to content

Instantly share code, notes, and snippets.

@cowboycoded
Created April 8, 2011 17:50
Show Gist options
  • Save cowboycoded/910364 to your computer and use it in GitHub Desktop.
Save cowboycoded/910364 to your computer and use it in GitHub Desktop.
dependency methods
#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