module Rigor::ModuleGraph::EdgeIO
JSONL reader / writer for Edge rows. Used by the plugin collector and the +rigor-module-graph+ renderer subcommands.
Public Instance Methods
Source
# 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
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.
Source
# 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
Stream +edges+ to +io+ as JSONL, deduping by Edge#dedup_key so re-runs donโt accumulate duplicate rows.