Class: GuiDebugger::DebugContext
- Inherits:
-
Object
- Object
- GuiDebugger::DebugContext
- Defined in:
- lib/gui_debugger/debug_context.rb
Instance Method Summary collapse
- #disp_source(index, range = 10) ⇒ Object
- #disp_stack_frame(index) ⇒ Object
- #file_path(stack) ⇒ Object
- #full_path(stack) ⇒ Object
-
#initialize(context, callers) ⇒ DebugContext
constructor
A new instance of DebugContext.
- #instance_variable_get(index, val) ⇒ Object
- #instance_variables(index) ⇒ Object
- #line_no(index) ⇒ Object
- #send_code(index, code) ⇒ Object
- #short_path(stack) ⇒ Object
- #source(index) ⇒ Object
- #stack_frames ⇒ Object
Constructor Details
#initialize(context, callers) ⇒ DebugContext
Returns a new instance of DebugContext.
4 5 6 7 |
# File 'lib/gui_debugger/debug_context.rb', line 4 def initialize(context, callers) @context = context @callers = callers end |
Instance Method Details
#disp_source(index, range = 10) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gui_debugger/debug_context.rb', line 17 def disp_source(index, range = 10) target_source = source(index) target_line_no = line_no(index) min_no = [target_line_no - range, 0].max max_no = [target_line_no + range, target_source.count].min highlight = (max_no < target_source.count) ? range : target_line_no text = target_source[min_no...max_no].join CodeRay.scan(text, :ruby).div(line_numbers: :inline, line_number_anchors: false, highlight_lines: [highlight]) end |
#disp_stack_frame(index) ⇒ Object
61 62 63 |
# File 'lib/gui_debugger/debug_context.rb', line 61 def disp_stack_frame(index) disp_source(index) end |
#file_path(stack) ⇒ Object
57 58 59 |
# File 'lib/gui_debugger/debug_context.rb', line 57 def file_path(stack) stack.eval("__FILE__") end |
#full_path(stack) ⇒ Object
46 47 48 |
# File 'lib/gui_debugger/debug_context.rb', line 46 def full_path(stack) file_path stack end |
#instance_variable_get(index, val) ⇒ Object
36 37 38 39 |
# File 'lib/gui_debugger/debug_context.rb', line 36 def instance_variable_get(index, val) str = @callers[index.to_i].eval("instance_variable_get('#{val}').inspect") GuiDebugger.escape str end |
#instance_variables(index) ⇒ Object
30 31 32 33 34 |
# File 'lib/gui_debugger/debug_context.rb', line 30 def instance_variables(index) vals = @callers[index.to_i].eval("instance_variables") arr = vals.select { |val| val.to_s.start_with?("@_") }.sort (vals - arr).sort + arr end |
#line_no(index) ⇒ Object
13 14 15 |
# File 'lib/gui_debugger/debug_context.rb', line 13 def line_no(index) @callers[index.to_i].eval("__LINE__") end |
#send_code(index, code) ⇒ Object
65 66 67 68 |
# File 'lib/gui_debugger/debug_context.rb', line 65 def send_code(index, code) return "" if code.blank? @callers[index.to_i].eval(URI.unescape(code)).to_s end |
#short_path(stack) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/gui_debugger/debug_context.rb', line 50 def short_path(stack) file_path(stack).tap do |path| Gem.path.each { |dir_path| path.sub!("#{dir_path}/gems/", "") } path.sub!("#{Rails.root.to_s}/", "") end end |
#source(index) ⇒ Object
9 10 11 |
# File 'lib/gui_debugger/debug_context.rb', line 9 def source(index) File.readlines(@callers[index.to_i].eval("__FILE__")) end |
#stack_frames ⇒ Object
41 42 43 44 |
# File 'lib/gui_debugger/debug_context.rb', line 41 def stack_frames frames = @callers.map.with_index { |stack, index| { path: short_path(stack), index: index } } frames.reject { |frame| frame[:index] == 0 } end |