Module: CoverMe::Results

Defined in:
lib/cover_me/results.rb

Class Method Summary collapse

Class Method Details

.merge_results!(cov_results, path = CoverMe.config.results.store) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cover_me/results.rb', line 14

def merge_results!(cov_results, path = CoverMe.config.results.store)
  
  data = CoverMe::Results.read_results(path)
  
  cov_results.each do |file, results|
    if data.has_key?(file)
      results.each_with_index do |result, i|
        summed_value = result # default
        if result.nil?
          summed_value = data[file][i]
        elsif !data[file][i].nil?
          summed_value = data[file][i] + result
        end
        data[file][i] = summed_value
      end
    else
      data[file] = results
    end
  end

  File.open(path, 'w') do |f|
    f.write(data.inspect)
  end
  
  return data
end

.read_results(path = CoverMe.config.results.store) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/cover_me/results.rb', line 6

def read_results(path = CoverMe.config.results.store)
  data = {}
  if File.exists?(path)
    data = eval(File.read(path)) || {}
  end
  return data
end