Class: Moult::Index
- Inherits:
-
Object
- Object
- Moult::Index
- Defined in:
- lib/moult/index.rb
Overview
The definition/reference index — Moult's adapter over the rubydex gem and
the only file that names Rubydex. Everything downstream consumes the
Moult-owned Definition value object, never a rubydex type, so the
backend is swappable (the "swap, not rewrite" invariant).
rubydex has two quirks this adapter normalises away (see test/test_index.rb):
- Its locations are 0-based; Moult/Prism are 1-based. We add 1 to line numbers so dead-code symbol ids line up with Scoring's hotspot ids.
- Method references are not resolved to their target declaration (only constants are). So a method is considered "referenced" when its bare name appears anywhere in the call-site collection. This is deliberately conservative: a name collision can only hide a dead method, never invent a false positive — the safe direction for a confidence-graded tool.
Defined Under Namespace
Classes: Definition
Constant Summary collapse
- BUILTIN_SCHEME =
"file:"
Instance Attribute Summary collapse
-
#override_of ⇒ Object
readonly
FQ name of the ancestor whose method this overrides/implements (reachable via that interface), else nil.
-
#reference_count ⇒ Object
readonly
resolvable usages of this definition.
-
#reference_paths ⇒ Object
readonly
root-relative paths that use it.
Class Method Summary collapse
-
.available? ⇒ Boolean
Whether the rubydex backend is loadable.
- .build(root:, paths:) ⇒ Index
Instance Method Summary collapse
-
#definitions ⇒ Array<Index::Definition>
Method + constant definition sites defined within the workspace, each with its resolved reference count.
-
#diagnostics ⇒ Array<String>
Human-readable index diagnostics (non-fatal).
-
#initialize(graph:, root:) ⇒ Index
constructor
A new instance of Index.
-
#kind(value) ⇒ Object
:method or :constant.
- #resolved? ⇒ Boolean
-
#singleton(value) ⇒ Object
true for Class.method / constants.
-
#visibility(value) ⇒ Object
:public, :private, :protected.
Constructor Details
#initialize(graph:, root:) ⇒ Index
Returns a new instance of Index.
64 65 66 67 68 69 70 71 72 |
# File 'lib/moult/index.rb', line 64 def initialize(graph:, root:) @graph = graph # rubydex reports canonical (symlink-resolved) paths, so the root must be # canonicalised too or workspace filtering misses everything on systems # where e.g. /tmp -> /private/tmp. @root = File.realpath(root.to_s) rescue Errno::ENOENT @root = root.to_s end |
Instance Attribute Details
#override_of ⇒ Object (readonly)
FQ name of the ancestor whose method this overrides/implements (reachable via that interface), else nil
33 34 35 36 37 |
# File 'lib/moult/index.rb', line 33 Definition = Struct.new( :symbol_id, :kind, :name, :unqualified_name, :owner, :visibility, :singleton, :span, :path, :reference_count, :reference_paths, :override_of ) |
#reference_count ⇒ Object (readonly)
resolvable usages of this definition
33 34 35 36 37 |
# File 'lib/moult/index.rb', line 33 Definition = Struct.new( :symbol_id, :kind, :name, :unqualified_name, :owner, :visibility, :singleton, :span, :path, :reference_count, :reference_paths, :override_of ) |
#reference_paths ⇒ Object (readonly)
root-relative paths that use it
33 34 35 36 37 |
# File 'lib/moult/index.rb', line 33 Definition = Struct.new( :symbol_id, :kind, :name, :unqualified_name, :owner, :visibility, :singleton, :span, :path, :reference_count, :reference_paths, :override_of ) |
Class Method Details
.available? ⇒ Boolean
Whether the rubydex backend is loadable. Always true once the gem is a hard dependency, but kept so live integration tests can skip cleanly.
56 57 58 59 60 61 |
# File 'lib/moult/index.rb', line 56 def available? require "rubydex" true rescue LoadError false end |
Instance Method Details
#definitions ⇒ Array<Index::Definition>
Returns method + constant definition sites defined within the workspace, each with its resolved reference count.
76 77 78 |
# File 'lib/moult/index.rb', line 76 def definitions @definitions ||= method_definitions + constant_definitions end |
#diagnostics ⇒ Array<String>
Returns human-readable index diagnostics (non-fatal).
85 86 87 88 89 |
# File 'lib/moult/index.rb', line 85 def diagnostics @graph.diagnostics.map(&:to_s) rescue [] end |
#kind=(value) ⇒ Object
:method or :constant
33 34 35 36 37 |
# File 'lib/moult/index.rb', line 33 Definition = Struct.new( :symbol_id, :kind, :name, :unqualified_name, :owner, :visibility, :singleton, :span, :path, :reference_count, :reference_paths, :override_of ) |
#resolved? ⇒ Boolean
80 81 82 |
# File 'lib/moult/index.rb', line 80 def resolved? true end |
#singleton=(value) ⇒ Object
true for Class.method / constants
33 34 35 36 37 |
# File 'lib/moult/index.rb', line 33 Definition = Struct.new( :symbol_id, :kind, :name, :unqualified_name, :owner, :visibility, :singleton, :span, :path, :reference_count, :reference_paths, :override_of ) |
#visibility=(value) ⇒ Object
:public, :private, :protected
33 34 35 36 37 |
# File 'lib/moult/index.rb', line 33 Definition = Struct.new( :symbol_id, :kind, :name, :unqualified_name, :owner, :visibility, :singleton, :span, :path, :reference_count, :reference_paths, :override_of ) |