Sha256: b2518633f29dbc92aaf7ded2c59a0e2376b5c7c3823484772e2023e225e630fa

Contents?: true

Size: 957 Bytes

Versions: 39

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

module Coverband
  module Utils
    class RelativeFileConverter
      def self.instance
        @instance ||= new(Coverband.configuration.all_root_paths)
      end

      def self.reset
        @instance = nil
      end

      def self.convert(file)
        instance.convert(file)
      end

      def initialize(roots)
        @cache = {}
        @roots = normalize(roots)
      end

      def convert(file)
        @cache[file] ||= begin
                           relative_file = file
                           @roots.each do |root|
                             relative_file = file.gsub(/^#{root}/, ".")
                             break relative_file if relative_file.start_with?(".")
                           end
                           relative_file
                         end
      end

      private

      def normalize(paths)
        paths.map { |root| File.expand_path(root) }
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
coverband-6.0.2 lib/coverband/utils/relative_file_converter.rb
coverband-6.0.1 lib/coverband/utils/relative_file_converter.rb
coverband-6.0.1.rc.1 lib/coverband/utils/relative_file_converter.rb
coverband-6.0.0 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.6.rc.6 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.3.2 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.6.rc.5 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.3.1 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.6.rc.4 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.6.rc.3 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.6.rc.2 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.6.rc.1 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.5 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.5.rc.3 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.5.rc.2 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.5.rc.1 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.4 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.3 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.2 lib/coverband/utils/relative_file_converter.rb
coverband-5.2.1 lib/coverband/utils/relative_file_converter.rb