Class: VisualizePackwerk::TeamGraph
- Inherits:
-
Object
- Object
- VisualizePackwerk::TeamGraph
- Extended by:
- T::Sig
- Includes:
- GraphInterface
- Defined in:
- lib/visualize_packwerk/team_graph.rb
Overview
A team graph reduces a PackageGraph by aggregating over packages owned by teams
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(team_nodes:) ⇒ TeamGraph
constructor
A new instance of TeamGraph.
- #nodes ⇒ Object
Constructor Details
#initialize(team_nodes:) ⇒ TeamGraph
Returns a new instance of TeamGraph.
17 18 19 |
# File 'lib/visualize_packwerk/team_graph.rb', line 17 def initialize(team_nodes:) @team_nodes = team_nodes end |
Class Method Details
.from_package_graph(package_graph) ⇒ Object
22 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 48 49 50 51 52 53 54 |
# File 'lib/visualize_packwerk/team_graph.rb', line 22 def self.from_package_graph(package_graph) team_nodes = T.let(Set.new, T::Set[TeamNode]) package_graph.package_nodes.group_by(&:team_name).each do |team, package_nodes_for_team| violations_by_team = {} package_nodes_for_team.map(&:violations_by_package).each do |new_violations_by_package| new_violations_by_package.each do |pack_name, count| # We first get the pack owner of the violated package other_package = package_graph.package_by_name(pack_name) next if other_package.nil? other_team = other_package.team_name violations_by_team[other_team] ||= 0 # Then we add the violations on that team together # TODO: We may want to ignore this if team == other_team to avoid arrows pointing to self, but maybe not! violations_by_team[other_team] += count end end dependencies = Set.new package_nodes_for_team.map(&:dependencies).reduce(Set.new, :+).each do |dependency| other_pack = package_graph.package_by_name(dependency) next if other_pack.nil? dependencies << other_pack.team_name end team_nodes << TeamNode.new( name: team, violations_by_team: violations_by_team, dependencies: dependencies ) end TeamGraph.new(team_nodes: team_nodes) end |
Instance Method Details
#nodes ⇒ Object
12 13 14 |
# File 'lib/visualize_packwerk/team_graph.rb', line 12 def nodes @team_nodes end |