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 |
# File 'lib/debug/source_repository.rb', line 14 def initialize # cache @cmap = ObjectSpace::WeakMap.new end |
Instance Method Details
#add(iseq, src) ⇒ Object
19 20 21 |
# File 'lib/debug/source_repository.rb', line 19 def add iseq, src # do nothing end |
#get(iseq) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/debug/source_repository.rb', line 23 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
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/debug/source_repository.rb', line 37 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 |