Sha256: 99c4216f760bd5686b531ed512784a7950541ec8870dea16dcf050afb9248899

Contents?: true

Size: 1.73 KB

Versions: 34

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: ntrue

require "coverband/utils/method_definition_scanner"

module Coverband
  module Utils
    module ArrayToTableInConsole
      refine Array do
        def to_table
          column_sizes =
            reduce([]) { |lengths, row|
              row.each_with_index.map do |iterand, index|
                [lengths[index] || 0, iterand.to_s.length].max
              end
            }
          puts head =
                 "-" * (column_sizes.inject(&:+) + (3 * column_sizes.count) + 1)
          each do |row|
            row = row.fill(nil, row.size..(column_sizes.size - 1))
            row =
              row.each_with_index.map { |v, i|
                v.to_s + " " * (column_sizes[i] - v.to_s.length)
              }
            puts "| " + row.join(" | ") + " |"
          end
          puts head
        end
      end
    end

    class DeadMethods
      using ArrayToTableInConsole
      def self.scan(file_path:, coverage:)
        MethodDefinitionScanner.scan(file_path).reject do |method_definition|
          method_definition.body.coverage?(coverage)
        end
      end

      def self.scan_all
        coverage = Coverband.configuration.store.coverage
        coverage.flat_map do |file_path, coverage|
          scan(file_path: file_path, coverage: coverage["data"])
        end
      end

      def self.output_all
        rows =
          scan_all.each_with_object(
            [%w[file class method line_number]]
          ) { |dead_method, rows|
            rows <<
              [
                dead_method.file_path,
                dead_method.class_name,
                dead_method.name,
                dead_method.first_line_number
              ]
          }
        rows.to_table
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
coverband-6.1.2 lib/coverband/utils/dead_methods.rb
coverband-6.1.2.rc.1 lib/coverband/utils/dead_methods.rb
coverband-6.1.1 lib/coverband/utils/dead_methods.rb
coverband-6.1.0 lib/coverband/utils/dead_methods.rb
coverband-6.0.3.rc.4 lib/coverband/utils/dead_methods.rb
coverband-6.0.3.rc.3 lib/coverband/utils/dead_methods.rb
coverband-6.0.3.rc.2 lib/coverband/utils/dead_methods.rb
coverband-6.0.3.rc.1 lib/coverband/utils/dead_methods.rb
coverband-6.0.2 lib/coverband/utils/dead_methods.rb
coverband-6.0.1 lib/coverband/utils/dead_methods.rb
coverband-6.0.1.rc.1 lib/coverband/utils/dead_methods.rb
coverband-6.0.0 lib/coverband/utils/dead_methods.rb
coverband-5.2.6.rc.6 lib/coverband/utils/dead_methods.rb
coverband-5.2.3.2 lib/coverband/utils/dead_methods.rb
coverband-5.2.6.rc.5 lib/coverband/utils/dead_methods.rb
coverband-5.2.3.1 lib/coverband/utils/dead_methods.rb
coverband-5.2.6.rc.4 lib/coverband/utils/dead_methods.rb
coverband-5.2.6.rc.3 lib/coverband/utils/dead_methods.rb
coverband-5.2.6.rc.2 lib/coverband/utils/dead_methods.rb
coverband-5.2.6.rc.1 lib/coverband/utils/dead_methods.rb