Created
March 9, 2018 03:36
-
-
Save mbklein/8af3853bda9120d2d65b5b7ded5e2a69 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class GemBacktracer | |
class << self | |
def cleanup(backtrace) | |
backtrace.collect do |line| | |
path = gem_path_for(line) | |
if path.nil? | |
line | |
else | |
"(#{bundle_paths[path]}):#{Pathname(line).relative_path_from(Pathname(path)).to_s}" | |
end | |
end | |
end | |
private | |
def bundle_paths | |
@bundle_paths ||= { Rails.root.to_s => Rails.application.class.name }.tap do |result| | |
all_specs = Bundler.load.specs.to_hash | |
all_specs.each_pair do |name, specs| | |
specs.each do |spec| | |
result[spec.full_gem_path] = spec.full_name | |
end | |
end | |
end | |
end | |
def gem_path_for(line) | |
bundle_paths.keys.find do |path| | |
line.start_with?(path) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment