Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Created June 24, 2009 01:21
Show Gist options
  • Save choonkeat/134946 to your computer and use it in GitHub Desktop.
Save choonkeat/134946 to your computer and use it in GitHub Desktop.
# 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