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_frame ⇒ Object
Constructor Details
#initialize(context, callers) ⇒ DebugContext
Returns a new instance of DebugContext.
6 7 8 9 |
# File 'lib/gui_debugger/debug_context.rb', line 6 def initialize(context, callers) @context = context @callers = callers end |
Instance Method Details
#disp_source(index, range = 10) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gui_debugger/debug_context.rb', line 19 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
62 63 64 |
# File 'lib/gui_debugger/debug_context.rb', line 62 def disp_stack_frame(index) disp_source(index) end |
#file_path(stack) ⇒ Object
58 59 60 |
# File 'lib/gui_debugger/debug_context.rb', line 58 def file_path(stack) stack.eval("__FILE__") end |
#full_path(stack) ⇒ Object
47 48 49 |
# File 'lib/gui_debugger/debug_context.rb', line 47 def full_path(stack) file_path stack end |
#instance_variable_get(index, val) ⇒ Object
38 39 40 41 |
# File 'lib/gui_debugger/debug_context.rb', line 38 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
32 33 34 35 36 |
# File 'lib/gui_debugger/debug_context.rb', line 32 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
15 16 17 |
# File 'lib/gui_debugger/debug_context.rb', line 15 def line_no(index) @callers[index.to_i].eval("__LINE__") end |
#send_code(index, code) ⇒ Object
66 67 68 69 70 |
# File 'lib/gui_debugger/debug_context.rb', line 66 def send_code(index, code) return "" if code.blank? code = URI.unescape(code) @callers[index.to_i].eval(code).to_s end |
#short_path(stack) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/gui_debugger/debug_context.rb', line 51 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
11 12 13 |
# File 'lib/gui_debugger/debug_context.rb', line 11 def source(index) File.readlines(@callers[index.to_i].eval("__FILE__")) end |
#stack_frame ⇒ Object
43 44 45 |
# File 'lib/gui_debugger/debug_context.rb', line 43 def stack_frame @callers.map { |stack| { short_path: short_path(stack) } } end |