module Rigor::ModuleGraph::CLI::EdgeFilters
Shared filter options reused by dot / mermaid / cycles / view.
Constants
- VALID_CONFIDENCES
- VALID_DIRECTIONS
- VALID_EDGE_SCOPES
- VALID_KINDS
Public Instance Methods
Source
# File lib/rigor/module_graph/cli.rb, line 117 def add_filter_options(opts, state) opts.on("--kind KINDS", Array, "Only render the listed edge kinds (#{VALID_KINDS.join(",")})") do |list| state[:kinds] = validate!(list, VALID_KINDS, "kind") end opts.on("--confidence LEVELS", Array, "Only render the listed confidence levels (#{VALID_CONFIDENCES.join(",")})") do |list| state[:confidences] = validate!(list, VALID_CONFIDENCES, "confidence") end opts.on("--from NAMES", Array, "Restrict the graph to nodes reachable from NAMES (comma-separated)") do |names| state[:from] = names end opts.on("--depth N", Integer, "Maximum hops from --from roots (default: unlimited)") do |n| state[:depth] = n end opts.on("--direction DIR", VALID_DIRECTIONS.map(&:to_s), "Direction to follow from --from roots (#{VALID_DIRECTIONS.join(", ")}; default: both)") do |dir| state[:direction] = dir.to_sym end opts.on("--edge-scope SCOPE", VALID_EDGE_SCOPES.map(&:to_s), "Edges to keep when --from is set: cluster keeps every edge whose " \ "endpoints both fall in the reachable node set; walk keeps only " \ "the edges the BFS actually traverses " \ "(#{VALID_EDGE_SCOPES.join("|")}; default: cluster)") do |scope| state[:edge_scope] = scope.to_sym end end
Source
# File lib/rigor/module_graph/cli.rb, line 105 def apply_filters(edges, kinds:, confidences:, from: nil, depth: nil, direction: :both, edge_scope: :cluster) edges = edges.select { |e| kinds.include?(e.kind) } if kinds edges = edges.select { |e| confidences.include?(e.confidence) } if confidences if from && !from.empty? edges = Reachability.filter( edges, roots: from, depth: depth, direction: direction, edge_scope: edge_scope ) end edges end
Source
# File lib/rigor/module_graph/cli.rb, line 147 def validate!(list, allowed, label) unknown = list - allowed unless unknown.empty? raise OptionParser::InvalidArgument, "unknown #{label}(s): #{unknown.join(",")}. Allowed: #{allowed.join(",")}" end list end