Class: ModularizationStatistics::Private::Metrics::NestedPacks
- Inherits:
-
Object
- Object
- ModularizationStatistics::Private::Metrics::NestedPacks
- Extended by:
- T::Sig
- Defined in:
- lib/modularization_statistics/private/metrics/nested_packs.rb
Defined Under Namespace
Classes: PackGroup
Class Method Summary collapse
Class Method Details
.get_nested_package_metrics(packages, app_name) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/modularization_statistics/private/metrics/nested_packs.rb', line 71 def self.get_nested_package_metrics(packages, app_name) all_metrics = [] app_level_tag = Tag.for('app', app_name) = T.let([app_level_tag], T::Array[Tag]) pack_groups = PackGroup.all_from(packages) all_pack_groups_count = pack_groups.count child_pack_count = pack_groups.sum(&:children_pack_count) parent_pack_count = pack_groups.count(&:has_parent?) all_cross_pack_group_violations = pack_groups.flat_map(&:cross_group_violations) all_metrics << GaugeMetric.for('all_pack_groups.count', all_pack_groups_count, ) all_metrics << GaugeMetric.for('child_packs.count', child_pack_count, ) all_metrics << GaugeMetric.for('parent_packs.count', parent_pack_count, ) all_metrics << GaugeMetric.for('all_pack_groups.privacy_violations.count', Metrics.file_count(all_cross_pack_group_violations.select(&:privacy?)), ) all_metrics << GaugeMetric.for('all_pack_groups.dependency_violations.count', Metrics.file_count(all_cross_pack_group_violations.select(&:dependency?)), )\ packs_by_group = {} pack_groups.each do |pack_group| pack_group.members.each do |member| packs_by_group[member.name] = pack_group.name end end inbound_violations_by_pack_group = {} all_cross_pack_group_violations.group_by(&:to_package_name).each do |to_package_name, violations| violations.each do |violation| pack_group_for_violation = packs_by_group[violation.to_package_name] inbound_violations_by_pack_group[pack_group_for_violation] ||= [] inbound_violations_by_pack_group[pack_group_for_violation] << violation end end pack_groups.each do |pack_group| = [ *, Tag.for('pack_group', Metrics.humanized_package_name(pack_group.name)), ] outbound_dependency_violations = pack_group.cross_group_violations.select(&:dependency?) inbound_privacy_violations = inbound_violations_by_pack_group.fetch(pack_group.name, []).select(&:privacy?) all_metrics << GaugeMetric.for('by_pack_group.outbound_dependency_violations.count', Metrics.file_count(outbound_dependency_violations), ) all_metrics << GaugeMetric.for('by_pack_group.inbound_privacy_violations.count', Metrics.file_count(inbound_privacy_violations), ) end pack_groups.each do |from_pack_group| violations_by_to_pack_group = from_pack_group.cross_group_violations.group_by do |violation| packs_by_group[violation.to_package_name] end violations_by_to_pack_group.each do |to_pack_group_name, violations| = [ *, Tag.for('pack_group', Metrics.humanized_package_name(from_pack_group.name)), Tag.for('to_pack_group', Metrics.humanized_package_name(to_pack_group_name)), ] all_metrics << GaugeMetric.for('by_pack_group.outbound_dependency_violations.per_pack_group.count', Metrics.file_count(violations.select(&:dependency?)), ) all_metrics << GaugeMetric.for('by_pack_group.outbound_privacy_violations.per_pack_group.count', Metrics.file_count(violations.select(&:privacy?)), ) end end all_metrics end |