Class: DEBUGGER__::SourceRepository
- Includes:
- Color
- Defined in:
- lib/debug/source_repository.rb
Defined Under Namespace
Classes: SrcInfo
Instance Method Summary collapse
- #add(iseq, src) ⇒ Object
- #get(iseq) ⇒ Object
- #get_colored(iseq) ⇒ Object
-
#initialize ⇒ SourceRepository
constructor
A new instance of SourceRepository.
Methods included from Color
#color_pp, #colored_inspect, #colorize, #colorize_blue, #colorize_code, #colorize_cyan, #colorize_dim, #colorize_magenta, #irb_colorize, #with_inspection_error_guard
Constructor Details
#initialize ⇒ SourceRepository
Returns a new instance of SourceRepository.
14 15 16 17 18 |
# File 'lib/debug/source_repository.rb', line 14 def initialize # cache @cmap = ObjectSpace::WeakMap.new @loaded_file_map = {} # path => nil end |
Instance Method Details
#add(iseq, src) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/debug/source_repository.rb', line 20 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 |
#get(iseq) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/debug/source_repository.rb', line 32 def get iseq return unless iseq if lines = iseq.script_lines&.map(&:chomp) lines else if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path) File.readlines(path, chomp: true) else nil end end end |
#get_colored(iseq) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/debug/source_repository.rb', line 46 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 |