class Rigor::ModuleGraph::CLI::ClassDiagramCmd
class-diagram renders a Mermaid +classDiagram+ document from the +edges.jsonl+ (the dependency graph) and the +nodes.jsonl+ (class declarations + methods + attributes). Phase 5 of the project — turns the dependency graph material into a UML-style class diagram.
Constants
- DEFAULT_NODES_PATH
Public Class Methods
Source
# File lib/rigor/module_graph/cli.rb, line 847 def initialize(stdout:, stderr:, stdin:) @stdout = stdout @stderr = stderr @stdin = stdin @options = { kinds: nil, confidences: nil, from: nil, depth: nil, direction: :both, edge_scope: :cluster, nodes_path: nil, include_methods: true, include_attributes: true, visibilities: %w[public protected private] } end
Public Instance Methods
Source
# File lib/rigor/module_graph/cli.rb, line 933 def default_nodes_for(edges_path) return DEFAULT_NODES_PATH unless edges_path File.join(File.dirname(edges_path), "nodes.jsonl") end
Source
# File lib/rigor/module_graph/cli.rb, line 901 def parse_options!(argv) parser = OptionParser.new do |opts| opts.banner = "Usage: rigor-module-graph class-diagram [options] [EDGES_FILE]" opts.on("--nodes PATH", "Path to the nodes JSONL (default: sibling of EDGES_FILE)") do |path| @options[:nodes_path] = path end opts.on("--no-methods", "Don't render methods inside class bodies") do @options[:include_methods] = false end opts.on("--no-attributes", "Don't render attributes inside class bodies") do @options[:include_attributes] = false end opts.on("--public-only", "Only show public members") do @options[:visibilities] = %w[public] end opts.on("--no-private", "Hide private members") do @options[:visibilities] = %w[public protected] end add_filter_options(opts, @options) opts.on("-h", "--help") do @stdout.puts opts exit 0 end end parser.parse!(argv) end
Source
# File lib/rigor/module_graph/cli.rb, line 939 def read_nodes(path) return [] unless path && File.exist?(path) File.open(path, "r") { |io| NodeIO.read(io) } end
Source
# File lib/rigor/module_graph/cli.rb, line 861 def run(argv) argv = argv.dup parse_options!(argv) edges_path = argv.shift io = edges_path ? File.open(edges_path, "r") : @stdin begin edges = EdgeIO.read(io) ensure io.close if edges_path && !io.closed? end edges = apply_filters( edges, kinds: @options[:kinds], confidences: @options[:confidences], from: @options[:from], depth: @options[:depth], direction: @options[:direction], edge_scope: @options[:edge_scope] ) nodes_path = @options[:nodes_path] || default_nodes_for(edges_path) nodes = read_nodes(nodes_path) out = Uml::ClassDiagram.render( edges, nodes, include_methods: @options[:include_methods], include_attributes: @options[:include_attributes], visibilities: @options[:visibilities] ) @stdout.print(out) 0 rescue OptionParser::ParseError => e @stderr.puts "rigor-module-graph class-diagram: #{e.message}" 2 rescue Errno::ENOENT => e @stderr.puts "rigor-module-graph class-diagram: #{e.message}" 1 end