Class: Trepan::Frame
- Inherits:
-
Object
- Object
- Trepan::Frame
- Defined in:
- app/frame.rb
Overview
Call-Stack frame methods
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#stack_size ⇒ Object
Returns the value of attribute stack_size.
Instance Method Summary collapse
- #args ⇒ Object
- #binding ⇒ Object
- #call_string(opts = {:maxwidth=>80, :callstyle => :last}) ⇒ Object
- #describe(opts = {:maxwidth => 80}) ⇒ Object
- #file ⇒ Object
-
#initialize(context, index = 0) ⇒ Frame
constructor
A new instance of Frame.
- #klass ⇒ Object
- #line ⇒ Object
- #local_variables ⇒ Object
- #method_name ⇒ Object
- #reset ⇒ Object
- #run(code, filename = nil) ⇒ Object
- #thread ⇒ Object
Constructor Details
#initialize(context, index = 0) ⇒ Frame
Returns a new instance of Frame.
7 8 9 10 11 12 |
# File 'app/frame.rb', line 7 def initialize(context, index=0) @context = context @index = index @stack_size = @context.stack_size reset end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
6 7 8 |
# File 'app/frame.rb', line 6 def index @index end |
#stack_size ⇒ Object
Returns the value of attribute stack_size.
6 7 8 |
# File 'app/frame.rb', line 6 def stack_size @stack_size end |
Instance Method Details
#args ⇒ Object
98 99 100 |
# File 'app/frame.rb', line 98 def args @args ||= @context.frame_args(@index) end |
#binding ⇒ Object
33 34 35 |
# File 'app/frame.rb', line 33 def binding @binding ||= @context.frame_binding(@index) end |
#call_string(opts = {:maxwidth=>80, :callstyle => :last}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/frame.rb', line 37 def call_string(opts={:maxwidth=>80, :callstyle => :last}) call_str = "" if method_name locals = local_variables if opts[:callstyle] != :short && klass if opts[:callstyle] == :tracked arg_info = @context.frame_args_info(@index) end call_str << "#{klass}." end call_str << method_name if args.any? call_str << "(" args.each_with_index do |name, i| case opts[:callstyle] when :short call_str += "%s, " % [name] when :last klass = locals[name].class if klass.inspect.size > 20+3 klass = klass.inspect[0..20]+"..." end call_str += "%s#%s, " % [name, klass] when :tracked if arg_info && arg_info.size > i call_str += "#{name}: #{arg_info[i].inspect}, " else call_str += "%s, " % name end end if call_str.size > opts[:maxwidth] # Strip off trailing ', ' if any but add stuff for later trunc call_str[-2..-1] = ",...XX" break end end call_str[-2..-1] = ")" # Strip off trailing ', ' if any end end return call_str end |
#describe(opts = {:maxwidth => 80}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/frame.rb', line 79 def describe(opts = {:maxwidth => 80}) str = '' # FIXME There seem to be bugs in showing call if # index != 0 call_str = index == 0 ? call_string(opts) : '' file = opts[:basename] ? File.basename(self.file) : self.file file_line = "at line %s:%d\n" % [file, line] unless call_str.empty? str += call_str + ' ' if str.size + call_str.size + 1 + file_line.size > opts[:maxwidth] str += "\n " else str += ' ' end end str += file_line str end |
#file ⇒ Object
102 103 104 |
# File 'app/frame.rb', line 102 def file @file ||= @context.frame_file(@index) end |
#klass ⇒ Object
106 107 108 |
# File 'app/frame.rb', line 106 def klass @klass ||= @context.frame_class(@index) end |
#line ⇒ Object
110 111 112 |
# File 'app/frame.rb', line 110 def line @line ||= @context.frame_line(@index) end |
#local_variables ⇒ Object
114 115 116 |
# File 'app/frame.rb', line 114 def local_variables @local_variables ||= @context.frame_locals(@index) end |
#method_name ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'app/frame.rb', line 118 def method_name if @method_name @method_name else m = @context.frame_method(@index) @method_name = m ? m.id2name : '' end end |
#reset ⇒ Object
14 15 16 17 |
# File 'app/frame.rb', line 14 def reset @binding = @klass = @file = @line = @local_variables = @method_name = @thread = nil end |
#run(code, filename = nil) ⇒ Object
28 29 30 31 |
# File 'app/frame.rb', line 28 def run(code, filename=nil) filename='(eval :%s)' % code unless filename eval(code, self.binding, filename) end |