Class: VisualizePackwerk::PackageGraph
- Inherits:
-
Object
- Object
- VisualizePackwerk::PackageGraph
- Extended by:
- T::Sig
- Includes:
- GraphInterface
- Defined in:
- lib/visualize_packwerk/package_graph.rb
Instance Attribute Summary collapse
-
#package_nodes ⇒ Object
readonly
Returns the value of attribute package_nodes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(package_nodes:) ⇒ PackageGraph
constructor
A new instance of PackageGraph.
- #nodes ⇒ Object
- #package_by_name(name) ⇒ Object
Constructor Details
#initialize(package_nodes:) ⇒ PackageGraph
Returns a new instance of PackageGraph.
17 18 19 20 |
# File 'lib/visualize_packwerk/package_graph.rb', line 17 def initialize(package_nodes:) @package_nodes = package_nodes @index_by_name = T.let({}, T::Hash[String, T.nilable(PackageNode)]) end |
Instance Attribute Details
#package_nodes ⇒ Object (readonly)
Returns the value of attribute package_nodes.
9 10 11 |
# File 'lib/visualize_packwerk/package_graph.rb', line 9 def package_nodes @package_nodes end |
Class Method Details
.construct ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/visualize_packwerk/package_graph.rb', line 23 def self.construct package_nodes = Set.new Packs.all.each do |p| owner = CodeOwnership.for_package(p) # Here we need to load the package violations and dependencies, # so we need to use ParsePackwerk to parse that information. package_info = ParsePackwerk.find(p.name) next unless package_info # This should not happen unless packs/parse_packwerk change implementation violations = package_info.violations violations_by_package = violations.group_by(&:to_package_name).transform_values(&:count) dependencies = package_info.dependencies package_nodes << PackageNode.new( name: p.name, team_name: owner&.name || 'Unknown', violations_by_package: violations_by_package, dependencies: Set.new(dependencies) ) end PackageGraph.new(package_nodes: package_nodes) end |
Instance Method Details
#nodes ⇒ Object
12 13 14 |
# File 'lib/visualize_packwerk/package_graph.rb', line 12 def nodes package_nodes end |
#package_by_name(name) ⇒ Object
50 51 52 |
# File 'lib/visualize_packwerk/package_graph.rb', line 50 def package_by_name(name) @index_by_name[name] ||= package_nodes.find { |node| node.name == name } end |