Sometimes you need to figure out where ruby code came from. For example, ActiveSupport showed up in our API and started breaking date handling and JSON. I could have used git bisect to find the commit that introduced the problem, but there’s a more direct way.
<cr:code lang=“ruby”> set_trace_func proc { |event, file, line, id, binding, classname| if id == :require args = binding.eval(“local_variables”).inject({}) do |vars, name| value = binding.eval name vars[name] = value unless value.nil? vars end
puts "req #{args.inspect}"
if defined? ActiveSupport
puts "AHA"
exit!
end
end } </cr:code>
Introduce this snippet before requiring anything. It’ll watch require statements, log them, and show you as soon as the offending constant appears. In this case, the culprit was require 'mail'
.
Post a Comment