Sha256: 2419cc8bb76cf28b8386e6b62a6ed4c78d1a31fe91c08c6fca29b841ed903093

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require 'yaml'

module Engines
  module Packwerk
    class Extractor
      METRICS = %i[
        packwerk_number_of_dependency_violations
        packwerk_number_of_privacy_violations
      ].freeze

      def initialize; end

      def call(provider)
        return unless requirements?

        metrics = METRICS.map do |metric|
          [metric, send(metric)]
        end.to_h

        provider.emit(metrics)
      end

      private

      def requirements?
        packwerk_files.length.positive?
      end

      # NOTE: This output file must be created by an external command
      def packwerk_files
        Dir.glob('./**/deprecated_references.yml')
      end

      def packwerk_number_of_dependency_violations
        packwerk_violations['dependency']
      end

      def packwerk_number_of_privacy_violations
        packwerk_violations['privacy']
      end

      def packwerk_items
        @packwerk_items ||= packwerk_files
          .map { |file| YAML.load_file(file) }
          .reduce({}, :merge)
          .map { |_key, values| values }
          .flatten
          .reduce({}, :merge)
      end

      def packwerk_violations
        packwerk_items
          .values
          .each_with_object(Hash.new(0)) do |offense, total|
            offense['violations'].each do |violation|
              total[violation] += 1
            end
          end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
codemonitor-0.3.6 engines/packwerk/extractor.rb
codemonitor-0.3.5 engines/packwerk/extractor.rb
codemonitor-0.3.4 engines/packwerk/extractor.rb
codemonitor-0.3.3 engines/packwerk/extractor.rb
codemonitor-0.3.2 engines/packwerk/extractor.rb
codemonitor-0.3.1 engines/packwerk/extractor.rb
codemonitor-0.3.0 engines/packwerk/extractor.rb