Class: Coverband::Utils::RelativeFileConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/coverband/utils/relative_file_converter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(roots) ⇒ RelativeFileConverter

Returns a new instance of RelativeFileConverter.



18
19
20
21
# File 'lib/coverband/utils/relative_file_converter.rb', line 18

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

Class Method Details

.convert(file) ⇒ Object



14
15
16
# File 'lib/coverband/utils/relative_file_converter.rb', line 14

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

.instanceObject



6
7
8
# File 'lib/coverband/utils/relative_file_converter.rb', line 6

def self.instance
  @instance ||= new(Coverband.configuration.all_root_paths)
end

.resetObject



10
11
12
# File 'lib/coverband/utils/relative_file_converter.rb', line 10

def self.reset
  @instance = nil
end

Instance Method Details

#convert(file) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/coverband/utils/relative_file_converter.rb', line 23

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