Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Replace ruby-graphviz with custom graph
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Mar 30, 2024
1 parent 5367706 commit c713d3c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
1 change: 0 additions & 1 deletion lib/mosaik.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

require "active_support/all"
require "git"
require "ruby-graphviz"
require "zeitwerk"

module MOSAIK
Expand Down
2 changes: 1 addition & 1 deletion lib/mosaik/collectors/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def call
next if value.zero?

# Add an edge from the node to the receiver
graph.add_edge(graph.find_node(a), graph.find_node(b), label: value)
graph.add_edge(a, b, label: value)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/mosaik/collectors/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ def call
private

def construct(constant)
# Get or create the node for the constant
node = graph.get_node(constant.name) || graph.add_node(constant.name)
# Find or create the node for the constant
caller = graph.find_or_add_vertex(constant.name)

# TODO: method-level granularity
constant.methods.each_value do |method|
method.references.each do |reference|
# Get or create the the receiver node
receiver = graph.get_node(reference.constant.name) || graph.add_node(reference.constant.name)
# Find or create the the receiver node
receiver = graph.find_or_add_vertex(reference.constant.name)

debug "Edge from #{constant.name} to #{reference.constant.name}##{reference.method}"
debug "Edge from #{caller.value} to #{receiver.value}##{reference.method}"

# Add an edge from the constant to the receiver
graph.add_edge(node, receiver, label: reference.method)
graph.add_edge(caller.value, receiver.value, label: reference.method)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mosaik/commands/collect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def prepare

def start
# Construct graph of classes based on file path
graph = GraphViz.new(:class_graph, type: :digraph)
graph = Graph::Graph.new

MOSAIK.configuration.files.each do |file|
# Resolve file path to class name
class_name = resolver.resolve(file)

# Add class to graph
graph.add_node(class_name)
graph.find_or_add_vertex(class_name)
end

# Collect data and add to graph
Expand Down
1 change: 0 additions & 1 deletion mosaik.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "git", "~> 1.19.1"
spec.add_runtime_dependency "packwerk", "~> 3.2.0"
spec.add_runtime_dependency "parser", "~> 3.3.0.5"
spec.add_runtime_dependency "ruby-graphviz", "~> 1.2.5"
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
end

0 comments on commit c713d3c

Please sign in to comment.