mirror of
https://github.com/github/rails.git
synced 2026-02-06 12:15:17 -05:00
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
This commit is contained in:
@@ -1,5 +1,24 @@
|
||||
*SVN*
|
||||
|
||||
* Added show_source_list and show_call_stack to breakpoints to make it easier to get context #5476 [takiuchi@drecom.co.jp]. Examples:
|
||||
|
||||
irb(#<TopController:0x40822a68>):002:0> show_source_list
|
||||
0001 class TopController < ApplicationController
|
||||
0002 def show
|
||||
0003-> breakpoint
|
||||
0004 end
|
||||
0005
|
||||
0006 def index
|
||||
0007 end
|
||||
0008
|
||||
=> "/path/to/rails/root/app/controllers/top_controller.rb"
|
||||
|
||||
irb(#<TopController:0x40822a68>):004:0> show_call_stack 3
|
||||
vendor/rails/railties/lib/breakpoint.rb:536:in `breakpoint'
|
||||
vendor/rails/railties/lib/breakpoint.rb:536:in `breakpoint'
|
||||
app/controllers/top_controller.rb:3:in `show'
|
||||
=> "/path/to/rails/root/app/controllers/top_controller.rb:3"
|
||||
|
||||
* Generate scaffold layout in subdirectory appropriate to its module nesting. #5511 [nils@alumni.rice.edu]
|
||||
|
||||
* Mongrel: script/server tails the rails log like it does with lighttpd. Prefer mongrel over lighttpd. #5541 [mike@clarkware.com]
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user