Module: Rigor::ModuleGraph::EdgeIO
- Defined in:
- lib/rigor/module_graph/edge.rb
Overview
JSONL reader / writer for Edge rows. Used by the plugin collector and the rigor-module-graph renderer subcommands.
Class Method Summary collapse
-
.read(io) ⇒ Object
Parse JSONL from
iointo Edge instances. -
.write(edges, io) ⇒ Object
Stream
edgestoioas JSONL, deduping by Edge#dedup_key so re-runs don’t accumulate duplicate rows.
Class Method Details
.read(io) ⇒ Object
Parse JSONL from io into Edge instances. Blank lines are skipped. Missing confidence defaults to “syntax” so the format stays backwards-compatible with earlier outputs.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/rigor/module_graph/edge.rb', line 159 def read(io) edges = [] io.each_line do |line| line = line.strip next if line.empty? row = JSON.parse(line) edges << Edge.build( from: row.fetch("from"), to: row.fetch("to"), kind: row.fetch("kind"), path: row["path"], line: row["line"], column: row["column"], confidence: row.fetch("confidence", "syntax"), raw: row["raw"] ) end edges end |
.write(edges, io) ⇒ Object
Stream edges to io as JSONL, deduping by Edge#dedup_key so re-runs don’t accumulate duplicate rows.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rigor/module_graph/edge.rb', line 145 def write(edges, io) seen = {} edges.each do |edge| key = edge.dedup_key next if seen[key] seen[key] = true io.puts(JSON.generate(edge.to_h)) end end |