Created
March 24, 2012 15:53
-
-
Save beathyate/2184524 to your computer and use it in GitHub Desktop.
Pequeño script para detectar quien require a iconv robado de acá http://stackoverflow.com/questions/7957888/tracing-dependency-loading-in-rails
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
# override Kernel#require to intercept stderr messages on require | |
# and raise a custom error if we find one mentioning 'iconv' | |
require "stringio" | |
class RequireError < StandardError | |
end | |
module Kernel | |
alias :the_original_require require | |
private :the_original_require | |
def capture_stderr | |
previous_stderr = $stderr | |
$stderr = StringIO.new | |
yield | |
$stderr.string | |
ensure | |
# Restore the previous value of stderr (typically equal to STDERR). | |
$stderr = previous_stderr | |
end | |
def require name | |
captured_output = capture_stderr { the_original_require(name) } | |
raise RequireError, 'iconv requirement found' if captured_output =~ /iconv/ | |
end | |
end | |
require 'bundler' | |
# load the list of Bundler requirements from the Gemfile | |
required_libraries = Bundler.definition.dependencies.map(&:name) | |
# loop through and require each, ignoring all errors other than | |
# our custom error | |
required_libraries.each do |requirement| | |
begin | |
require requirement | |
rescue Exception => e | |
raise e if e.class == RequireError | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment