123456789_123456789_123456789_123456789_123456789_

Class: DEBUGGER__::SourceRepository

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Color
Inherits: Object
Defined in: lib/debug/source_repository.rb

Class Method Summary

Instance Method Summary

Color - Included

#color_pp

See additional method definition at line 50.

#colored_inspect,
#colorize

See additional method definition at line 36.

#colorize_blue,
#colorize_code

See additional method definition at line 79.

#colorize_cyan, #colorize_dim, #colorize_magenta,
#irb_colorize

See additional method definition at line 27.

#with_inspection_error_guard

Constructor Details

.newSourceRepository

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 30

def initialize
  # cache
  @cmap = ObjectSpace::WeakMap.new
  @loaded_file_map = {} # path => nil
end

#initializeSourceRepository

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 73

def initialize
  @files = {} # filename => SrcInfo
end

Instance Method Details

#add(iseq, src)

See additional method definition at line 36.

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 77

def add iseq, src
  # do nothing
  if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
    if @loaded_file_map.has_key? path
      return path, true # reloaded
    else
      @loaded_file_map[path] = path
      return path, false
    end
  end
end

#add_iseq(iseq, src) (private)

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 104

private def add_iseq iseq, src
  line = iseq.first_line
  if line > 1
    src = ("\n" * (line - 1)) + src
  end

  si = SrcInfo.new(src.each_line.map{|l| l.chomp})
  all_iseq(iseq).each{|e|
    e.instance_variable_set(:@debugger_si, si)
    e.freeze
  }
end

#add_path(path) (private)

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 117

private def add_path path
  src_lines = File.readlines(path, chomp: true)
  @files[path] = SrcInfo.new(src_lines)
rescue SystemCallError
end

#all_iseq(iseq, rs = []) (private)

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 96

private def all_iseq iseq, rs = []
  rs << iseq
  iseq.each_child{|ci|
    all_iseq(ci, rs)
  }
  rs
end

#file_src(iseq)

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 9

def file_src iseq
  if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
    File.readlines(path, chomp: true)
  end
end

#get(iseq)

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 15

def get iseq
  return unless iseq

  if CONFIG[:show_evaledsrc]
    orig_src(iseq) || file_src(iseq)
  else
    file_src(iseq) || orig_src(iseq)
  end
end

#get_colored(iseq)

See additional method definition at line 58.

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 141

def get_colored iseq
  if lines = @cmap[iseq]
    lines
  else
    if src_lines = get(iseq)
      @cmap[iseq] = colorize_code(src_lines.join("\n")).lines
    else
      nil
    end
  end
end

#get_si(iseq) (private)

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 123

private def get_si iseq
  return unless iseq

  if iseq.instance_variable_defined?(:@debugger_si)
    iseq.instance_variable_get(:@debugger_si)
  elsif @files.has_key?(path = (iseq.absolute_path || iseq.path))
    @files[path]
  elsif path
    add_path(path)
  end
end

#orig_src(iseq)

See additional method definition at line 48.

[ GitHub ]

  
# File 'lib/debug/source_repository.rb', line 135

def orig_src iseq
  lines = iseq.script_lines&.map(&:chomp)
  line = iseq.first_line
  if line > 1
    lines = [*([''] * (line - 1)), *lines]
  else
    lines
  end
end