Created
June 24, 2009 01:21
-
-
Save choonkeat/134946 to your computer and use it in GitHub Desktop.
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
# Stick this at the bottom of environment.rb | |
# Run through your app, and "require.log.rb" will capture the libs that are loaded after-the-fact | |
# Then you can decide if you wish to load all these libs upfront. | |
# Possibly avoids the infamous "Expected x.rb to define x" errors | |
if ENV['LOAD_REQUIRE_LOG'] && File.exists?("require.log.rb") | |
require "require.log.rb" | |
$stderr.puts "Loaded require.log.rb" | |
end | |
Kernel.class_eval do | |
alias :_original_require :require | |
def require(*args) | |
logged_string = args.collect {|path| "require '#{path}'\n # #{caller.join("\n # ")}" }.join("\n") + "\n" | |
if ENV['LOAD_REQUIRE_LOG'] && File.exists?("require.log.rb") | |
$stderr.puts logged_string | |
else | |
open("require.log.rb", "a") {|f| f.write(logged_string) } | |
end | |
_original_require(*args) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment