Sha256: 22571951298a2da2d82afe5ef3d577a9b6c9d7b992eccf5e80298cb4e28a773a

Contents?: true

Size: 1.71 KB

Versions: 28

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

#
# Applies the configured groups to the given array of Coverband::SourceFile items
#
module Coverband
  module Utils
    class FileGroups
      def initialize(files)
        @grouped = {}
        @files = files
        filter_to_groups
      end

      def grouped_results
        @grouped
      end

      private

      def filter_to_groups
        grouped_files = []
        Coverband.configuration.groups.each do |name, filter|
          if name == 'Gems'
            gem_lists = gem_files(name, filter)
            grouped_files.concat(gem_lists.flatten) if gem_lists.flatten.any?
          else
            app_files(name, filter)
            grouped_files += @grouped[name]
          end
        end
        if !Coverband.configuration.groups.empty? && !(other_files = @files.reject do |source_file|
                                                         grouped_files.include?(source_file)
                                                       end).empty?
          @grouped['Ungrouped'] = Coverband::Utils::FileList.new(other_files)
        end
      end

      def gem_files(name, filter)
        grouped_gems = @files.select { |source_file| source_file.filename =~ /#{filter}/ }.group_by(&:gem_name)
        gem_lists = grouped_gems.values.map { |gem_files| Coverband::Utils::FileList.new(gem_files) }
        @grouped[name] = Coverband::Utils::GemList.new(gem_lists) if gem_lists.flatten.any?
        gem_lists
      end

      def app_files(name, filter)
        @grouped[name] = Coverband::Utils::FileList.new(@files.select do |source_file|
          source_file.filename =~ /#{filter}/ && source_file.filename !~ /#{Coverband.configuration.gem_paths.first}/
        end)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
coverband-4.2.7 lib/coverband/utils/file_groups.rb
coverband-4.2.7.rc.1 lib/coverband/utils/file_groups.rb
coverband-4.2.6 lib/coverband/utils/file_groups.rb
coverband-4.2.5 lib/coverband/utils/file_groups.rb
coverband-4.2.5.rc.2 lib/coverband/utils/file_groups.rb
coverband-4.2.5.rc.1 lib/coverband/utils/file_groups.rb
coverband-4.2.4 lib/coverband/utils/file_groups.rb
coverband-4.2.4.rc.3 lib/coverband/utils/file_groups.rb
coverband-4.2.4.rc.2 lib/coverband/utils/file_groups.rb
coverband-4.2.4.rc.1 lib/coverband/utils/file_groups.rb
coverband-4.2.3 lib/coverband/utils/file_groups.rb
coverband-4.2.3.rc.2 lib/coverband/utils/file_groups.rb
coverband-4.2.3.rc.1 lib/coverband/utils/file_groups.rb
coverband-4.2.2 lib/coverband/utils/file_groups.rb
coverband-4.2.2.rc.1 lib/coverband/utils/file_groups.rb
coverband-4.2.1 lib/coverband/utils/file_groups.rb
coverband-4.2.1.rc4 lib/coverband/utils/file_groups.rb
coverband-4.2.1.rc3 lib/coverband/utils/file_groups.rb
coverband-4.2.1.rc2 lib/coverband/utils/file_groups.rb
coverband-4.2.1.rc1 lib/coverband/utils/file_groups.rb