Class: Moult::Duplication::MethodIndex
- Inherits:
-
Object
- Object
- Moult::Duplication::MethodIndex
- Defined in:
- lib/moult/duplication.rb
Overview
Best-effort line -> enclosing-method resolution, reusing the Prism Parser so the minted ids are byte-identical to the hotspots/deadcode join keys. flay reports a clone's start line only; we attribute it to the innermost method whose span contains that line. Files are parsed lazily and memoised; a fragment outside any method (top-level code, a whole class) resolves to nil.
Instance Method Summary collapse
-
#initialize(root:, files:) ⇒ MethodIndex
constructor
A new instance of MethodIndex.
-
#symbol_id_at(rel_path, line) ⇒ String?
Symbol_id of the innermost containing method, or nil.
Constructor Details
#initialize(root:, files:) ⇒ MethodIndex
Returns a new instance of MethodIndex.
77 78 79 80 |
# File 'lib/moult/duplication.rb', line 77 def initialize(root:, files:) @abs_by_rel = files.to_h { |abs| [SymbolId.relative_path(abs, root), abs] } @cache = {} end |
Instance Method Details
#symbol_id_at(rel_path, line) ⇒ String?
Returns symbol_id of the innermost containing method, or nil.
83 84 85 86 87 |
# File 'lib/moult/duplication.rb', line 83 def symbol_id_at(rel_path, line) method = enclosing_method(rel_path, line) return nil unless method SymbolId.for(path: rel_path, start_line: method.span.start_line, fqname: method.name) end |