Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4545

Show
Ignore:
Timestamp:
07/05/06 02:02:30 (3 years ago)
Author:
david
Message:

Added show_source_list and show_call_stack to breakpoints to make it easier to get context (closes #5476) [takiuchi@drecom.co.jp]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/railties/CHANGELOG

    r4527 r4545  
    11*SVN* 
     2 
     3* Added show_source_list and show_call_stack to breakpoints to make it easier to get context #5476 [takiuchi@drecom.co.jp]. Examples: 
     4 
     5    irb(#<TopController:0x40822a68>):002:0> show_source_list 
     6    0001  class TopController < ApplicationController 
     7    0002    def show 
     8    0003->    breakpoint 
     9    0004    end 
     10    0005     
     11    0006    def index 
     12    0007    end 
     13    0008     
     14    => "/path/to/rails/root/app/controllers/top_controller.rb" 
     15 
     16    irb(#<TopController:0x40822a68>):004:0> show_call_stack 3 
     17    vendor/rails/railties/lib/breakpoint.rb:536:in `breakpoint' 
     18    vendor/rails/railties/lib/breakpoint.rb:536:in `breakpoint' 
     19    app/controllers/top_controller.rb:3:in `show' 
     20    => "/path/to/rails/root/app/controllers/top_controller.rb:3" 
    221 
    322* Generate scaffold layout in subdirectory appropriate to its module nesting. #5511 [nils@alumni.rice.edu] 
  • trunk/railties/lib/breakpoint.rb

    r2637 r4545  
    177177        return result 
    178178      end 
     179    end 
     180 
     181    # Prints the source code surrounding the location where the 
     182    # breakpoint was issued. 
     183    def show_source_list(context = 5) 
     184      start_line, break_line, result = source_lines(context, true) 
     185      offset = [(break_line + context).to_s.length, 4].max 
     186      result.each_with_index do |line, i| 
     187        mark = (start_line + i == break_line ? '->' : '  ') 
     188        client.puts("%0#{offset}d%s#{line}" % [start_line + i, mark]) 
     189      end 
     190      Pathname.new(@__bp_file).cleanpath.to_s 
     191    end 
     192 
     193    # Prints the call stack. 
     194    def show_call_stack(depth = 10) 
     195      base = Pathname.new(RAILS_ROOT).cleanpath.to_s 
     196      caller[1..depth].each do |line| 
     197        line.sub!(/^[^:]*/) do |path| 
     198          Pathname.new(path).cleanpath.to_s 
     199        end 
     200        client.puts(line.index(base) == 0 ? line[(base.length + 1)..-1] : line) 
     201      end 
     202      "#{Pathname.new(@__bp_file).cleanpath.to_s}:#{@__bp_line}" 
    179203    end 
    180204