diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-07-05 02:02:30 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-07-05 02:02:30 +0000 |
commit | 06411f4261cd0507be7b25883ed761ece9e8337f (patch) | |
tree | ce0c586aa2b656b3e11950d1e94a4ef344f09cf5 /railties/lib | |
parent | 750ca7998bc3d749f54a767065693cb94c2f6f47 (diff) | |
download | rails-06411f4261cd0507be7b25883ed761ece9e8337f.tar.gz rails-06411f4261cd0507be7b25883ed761ece9e8337f.tar.bz2 rails-06411f4261cd0507be7b25883ed761ece9e8337f.zip |
Added show_source_list and show_call_stack to breakpoints to make it easier to get context (closes #5476) [takiuchi@drecom.co.jp]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4545 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/breakpoint.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/railties/lib/breakpoint.rb b/railties/lib/breakpoint.rb index 327e43e8e3..60f7fdbbef 100644 --- a/railties/lib/breakpoint.rb +++ b/railties/lib/breakpoint.rb @@ -178,6 +178,30 @@ module Breakpoint end
end
+ # Prints the source code surrounding the location where the
+ # breakpoint was issued.
+ def show_source_list(context = 5)
+ start_line, break_line, result = source_lines(context, true)
+ offset = [(break_line + context).to_s.length, 4].max
+ result.each_with_index do |line, i|
+ mark = (start_line + i == break_line ? '->' : ' ')
+ client.puts("%0#{offset}d%s#{line}" % [start_line + i, mark])
+ end
+ Pathname.new(@__bp_file).cleanpath.to_s
+ end
+
+ # Prints the call stack.
+ def show_call_stack(depth = 10)
+ base = Pathname.new(RAILS_ROOT).cleanpath.to_s
+ caller[1..depth].each do |line|
+ line.sub!(/^[^:]*/) do |path|
+ Pathname.new(path).cleanpath.to_s
+ end
+ client.puts(line.index(base) == 0 ? line[(base.length + 1)..-1] : line)
+ end
+ "#{Pathname.new(@__bp_file).cleanpath.to_s}:#{@__bp_line}"
+ end
+
# Lets an object that will forward method calls to the breakpoint
# client. This is useful for outputting longer things at the client
# and so on. You can for example do these things:
|