Class: Rigor::ModuleGraph::Edge
- Inherits:
-
Object
- Object
- Rigor::ModuleGraph::Edge
- Defined in:
- lib/rigor/module_graph/edge.rb
Overview
A single dependency edge between two constants.
Carries the dependency itself (from, to, kind, confidence), the source position it was extracted from (path, line, column), and the raw source slice (raw) when the resolution went through a fallback path. Edge is a Data subclass — every instance is immutable.
Two serialisation shapes
to_message_payload-
What the plugin embeds in a diagnostic’s
messagefield. The collector reconstructs an Edge from this payload plus the diagnostic’s ownpath/line/column, so the payload omits position to keep the message compact. to_h-
What the JSONL writer dumps to disk. Full row, with
path/line/columnincluded.
Dedup key
dedup_key ignores path and line so the same logical edge declared in two files (or surfaced by two re-runs of rigor check) collapses to one row. The dedup_key member at the end is internal: it’s the cached “\x00”-joined key string the renderers’ dedup loops use for Hash lookups. Storing it on the value pays for itself once a few hundred edges flow through any rendering / IO path.
Constant Summary collapse
- KINDS =
Same as Rigor::ModuleGraph::EDGE_KINDS; exposed on the class so callers can write
Edge::KINDS. EDGE_KINDS- CONFIDENCES =
Same as Rigor::ModuleGraph::EDGE_CONFIDENCES; exposed on the class so callers can write
Edge::CONFIDENCES. EDGE_CONFIDENCES
Class Method Summary collapse
-
.build(from:, to:, kind:, path: nil, line: nil, column: nil, confidence: "syntax", raw: nil) ⇒ Object
Build an Edge, validating
kindandconfidenceagainst the canonical lists and frozen-stringifyingfrom/to. -
.validate_confidence!(confidence) ⇒ Object
:nodoc:.
-
.validate_kind!(kind) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#to_h ⇒ Object
The on-disk JSONL row.
- #to_json(*args) ⇒ Object
-
#to_message_payload ⇒ Object
The payload embedded in a
:infodiagnostic’s message.
Class Method Details
.build(from:, to:, kind:, path: nil, line: nil, column: nil, confidence: "syntax", raw: nil) ⇒ Object
Build an Edge, validating kind and confidence against the canonical lists and frozen-stringifying from / to. Raises ArgumentError on unknown values.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rigor/module_graph/edge.rb', line 75 def self.build(from:, to:, kind:, path: nil, line: nil, column: nil, confidence: "syntax", raw: nil) from = from.to_s.freeze to = to.to_s.freeze kind = validate_kind!(kind) confidence = validate_confidence!(confidence) new( from: from, to: to, kind: kind, path: path, line: line, column: column, confidence: confidence, raw: raw, dedup_key: -"#{from}\x00#{to}\x00#{kind}\x00#{confidence}" ) end |
.validate_confidence!(confidence) ⇒ Object
:nodoc:
100 101 102 103 104 105 |
# File 'lib/rigor/module_graph/edge.rb', line 100 def self.validate_confidence!(confidence) # :nodoc: confidence = confidence.to_s return confidence if CONFIDENCES.include?(confidence) raise ArgumentError, "unknown confidence #{confidence.inspect}; expected one of #{CONFIDENCES.inspect}" end |
Instance Method Details
#to_h ⇒ Object
The on-disk JSONL row. Nil-valued positional fields are omitted so a stand-alone edge (e.g. constructed in a test without a path) does not leak “path”:null noise.
110 111 112 113 114 115 116 117 118 |
# File 'lib/rigor/module_graph/edge.rb', line 110 def to_h h = { "from" => from, "to" => to, "kind" => kind } h["path"] = path if path h["line"] = line if line h["column"] = column if column h["confidence"] = confidence h["raw"] = raw if raw h end |
#to_json(*args) ⇒ Object
130 131 132 |
# File 'lib/rigor/module_graph/edge.rb', line 130 def to_json(*args) JSON.generate(to_h, *args) end |
#to_message_payload ⇒ Object
The payload embedded in a :info diagnostic’s message. Position is intentionally absent — the diagnostic carries its own path/line/column, so duplicating them here would just bloat output.
124 125 126 127 128 |
# File 'lib/rigor/module_graph/edge.rb', line 124 def h = { "from" => from, "to" => to, "kind" => kind, "confidence" => confidence } h["raw"] = raw if raw h end |