Skip to content

Instantly share code, notes, and snippets.

@beathyate
Created March 24, 2012 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beathyate/2184524 to your computer and use it in GitHub Desktop.
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
# 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