Sha256: 1274720dbc7d6ba6b2cd7beb5de7e62aa82f7b185dd13137d6626984d8246c24

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 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)
        metrics = METRICS.map do |metric|
          [metric, send(metric)]
        end.to_h

        provider.emit(metrics)
      end

      def requirements?
        packwerk_files.length.positive?
      end

      private

      def packwerk_files
        Dir.glob('./**/package_todo.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

1 entries across 1 versions & 1 rubygems

Version Path
codemonitor-0.6.4 engines/packwerk/extractor.rb