Skip to content

Instantly share code, notes, and snippets.

@rhettc
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhettc/8792937 to your computer and use it in GitHub Desktop.
Save rhettc/8792937 to your computer and use it in GitHub Desktop.
def app_path
unless @app_path
git_root = `git rev-parse --show-toplevel`.chomp
@app_path = $?.success? ? git_root : Dir.pwd
end
@app_path
end
class Exception
def quick_trace(lines = 5)
beautify(backtrace.take lines)
end
# filter the backtrace to show lines from files in the 'current app'
def app_trace
beautify(backtrace.grep /#{app_path}/)
end
def filter_path(paths)
paths.map { |path| path.gsub app_path, ''}
end
# remove uninteresting path segments and prepend the result to make our printed result aligned
def beautify(entries)
filter_path(entries).unshift ''
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment