Sha256: ae1ad26a7d8304750e9f66b12b76e9cdc2da9fe93f7b0b3f1642186f79f944e9

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'pronto'
require_relative 'message_creator'

module Pronto
  # Performs incremental quality reporting for the bigfiles gem
  class BigFiles < Runner
    # Inspects patches and returns a Pronto::Message class when appropriate
    class PatchInspector
      def initialize(bigfiles_result,
                     message_creator_class: MessageCreator,
                     bigfiles_config:)
        @message_creator_class = message_creator_class
        @bigfiles_result = bigfiles_result
        @bigfiles_config = bigfiles_config
        @message_creator =
          @message_creator_class.new(@bigfiles_config.num_files,
                                     total_lines,
                                     @bigfiles_config.high_water_mark)
      end

      def under_limit?
        @bigfiles_config.under_limit?(total_lines)
      end

      def total_lines
        @bigfiles_result.map(&:num_lines).reduce(:+)
      end

      def inspect_patch(patch_wrapper)
        path = patch_wrapper.path
        file_with_line = @bigfiles_result.find { |f| f.filename == path }

        return if file_with_line.nil?

        return unless patch_wrapper.added_to?

        return if under_limit?

        @message_creator.create_message(patch_wrapper, file_with_line.num_lines)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pronto-bigfiles-0.1.2 lib/pronto/bigfiles/patch_inspector.rb
pronto-bigfiles-0.1.1 lib/pronto/bigfiles/patch_inspector.rb
pronto-bigfiles-0.1.0 lib/pronto/bigfiles/patch_inspector.rb