Class: ModularizationStatistics::Private::Metrics::PackwerkCheckerUsage

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/modularization_statistics/private/metrics/packwerk_checker_usage.rb

Defined Under Namespace

Classes: PackwerkChecker

Class Method Summary collapse

Class Method Details

.get_checker_metrics(prefix, packages, package_tags) ⇒ Object



19
20
21
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
# File 'lib/modularization_statistics/private/metrics/packwerk_checker_usage.rb', line 19

def self.get_checker_metrics(prefix, packages, package_tags)
  metrics = T.let([], T::Array[GaugeMetric])

  checkers = [
    PackwerkChecker.new(setting: 'enforce_dependencies', strict_mode: 'enforce_dependencies_strictly'),
    PackwerkChecker.new(setting: 'enforce_privacy', strict_mode: 'enforce_privacy_strictly')
  ]

  checkers.each do |checker|
    ['false', 'true', 'strict'].each do |enabled_mode|
      count_of_packages = ParsePackwerk.all.count do |package|
        strict_mode = package.[checker.strict_mode]
        enabled = YAML.load_file(package.yml)[checker.setting]
        case enabled_mode
        when 'false'
          !enabled
        when 'true'
          enabled && !strict_mode
        when 'strict'
          !!strict_mode
        end
      end

      metric_name = "#{prefix}.packwerk_checkers.#{checker.setting}.#{enabled_mode}.count"
      metrics << GaugeMetric.for(metric_name, count_of_packages, package_tags)
    end
  end

  metrics
end