123456789_123456789_123456789_123456789_123456789_

Class: SimpleCov::ResultAdapter

Relationships & Source Files
Inherits: Object
Defined in: lib/simplecov/result_adapter.rb

Overview

Responsible for adapting the format of the coverage result whether it’s default or with statistics

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(result) ⇒ ResultAdapter

[ GitHub ]

  
# File 'lib/simplecov/result_adapter.rb', line 10

def initialize(result)
  @result = result
end

Class Method Details

.call(*args)

[ GitHub ]

  
# File 'lib/simplecov/result_adapter.rb', line 14

def self.call(*args)
  new(*args).adapt
end

Instance Attribute Details

#result (readonly)

[ GitHub ]

  
# File 'lib/simplecov/result_adapter.rb', line 8

attr_reader :result

Instance Method Details

#adapt

[ GitHub ]

  
# File 'lib/simplecov/result_adapter.rb', line 18

def adapt
  return unless result

  result.each_with_object({}) do |(file_name, cover_statistic), adapted_result|
    if cover_statistic.is_a?(Array)
      adapted_result.merge!(file_name => {"lines" => cover_statistic})
    else
      adapt_oneshot_lines_if_needed(file_name, cover_statistic)
      adapted_result.merge!(file_name => cover_statistic)
    end
  end
end

#adapt_oneshot_lines_if_needed(file_name, cover_statistic) (private)

[ GitHub ]

  
# File 'lib/simplecov/result_adapter.rb', line 33

def adapt_oneshot_lines_if_needed(file_name, cover_statistic)
  if cover_statistic.key?(:oneshot_lines)
    line_stub = Coverage.line_stub(file_name)
    oneshot_lines = cover_statistic.delete(:oneshot_lines)
    oneshot_lines.each do |covered_line|
      line_stub[covered_line - 1] = 1
    end
    cover_statistic[:lines] = line_stub
  else
    cover_statistic
  end
end