lib/graphwerk/builders/graph.rb in graphwerk-1.1.0 vs lib/graphwerk/builders/graph.rb in graphwerk-1.2.0
- old
+ new
@@ -7,19 +7,21 @@
extend T::Sig
OptionsShape = T.type_alias {
{
layout: Graphwerk::Layout,
+ deprecated_references_color: String,
application: T::Hash[Symbol, Object],
graph: T::Hash[Symbol, Object],
node: T::Hash[Symbol, Object],
edge: T::Hash[Symbol, Object]
}
}
DEFAULT_OPTIONS = T.let({
layout: Graphwerk::Layout::Dot,
+ deprecated_references_color: 'red',
application: {
style: 'filled',
fillcolor: '#333333',
fontcolor: 'white'
},
@@ -39,14 +41,15 @@
edge: {
len: '0.4'
}
}, OptionsShape)
- sig { params(package_set: Packwerk::PackageSet, options: T::Hash[Symbol, Object]).void }
- def initialize(package_set, options: {})
+ sig { params(package_set: Packwerk::PackageSet, options: T::Hash[Symbol, Object], root_path: Pathname).void }
+ def initialize(package_set, options: {}, root_path: Pathname.new(ENV['PWD']))
@package_set = package_set
@options = T.let(DEFAULT_OPTIONS.deep_merge(options), OptionsShape)
+ @root_path = root_path
@graph = T.let(build_empty_graph, GraphViz)
@nodes = T.let(build_empty_nodes, T::Hash[String, GraphViz::Node])
end
sig { returns(GraphViz) }
@@ -83,11 +86,14 @@
@options[:edge].each_pair { |k,v| @graph.edge[k] =v }
end
sig { void }
def add_package_dependencies_to_graph
- packages.each { |package| draw_dependencies(package) }
+ packages.each do |package|
+ draw_dependencies(package)
+ draw_deprecated_references(package)
+ end
end
sig { void }
def add_packages_to_graph
packages.each do |package|
@@ -100,13 +106,24 @@
package.dependencies.each do |dependency|
@graph.add_edges(@nodes[package.name], @nodes[dependency], color: package.color)
end
end
+ sig { params(package: Presenters::Package).void }
+ def draw_deprecated_references(package)
+ package.deprecated_references.each do |reference|
+ @graph.add_edges(
+ @nodes[package.name],
+ @nodes[reference],
+ color: @options[:deprecated_references_color]
+ )
+ end
+ end
+
sig { returns(T::Array[Presenters::Package]) }
def packages
@packages = T.let(@packages, T.nilable(T::Array[Presenters::Package]))
- @packages ||= @package_set.map { |package| Presenters::Package.new(package) }
+ @packages ||= @package_set.map { |package| Presenters::Package.new(package, @root_path) }
end
end
end
end