Class: SimpleCov::Formatter::JSONFormatter::SourceFileFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/formatter/json_formatter/source_file_formatter.rb

Overview

Renders a single ‘SimpleCov::SourceFile` as the per-file payload in coverage.json: source code plus per-enabled-criterion arrays and totals.

Instance Method Summary collapse

Constructor Details

#initialize(source_file, include_source: true) ⇒ SourceFileFormatter

Returns a new instance of SourceFileFormatter.



10
11
12
13
# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 10

def initialize(source_file, include_source: true)
  @source_file = source_file
  @include_source = include_source
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
# File 'lib/simplecov/formatter/json_formatter/source_file_formatter.rb', line 15

def call
  result = @include_source ? format_source_code : {}
  result.merge!(line_coverage_section) if line_coverage_enabled?
  result.merge!(branch_coverage_section) if SimpleCov.branch_coverage?
  result.merge!(method_coverage_section) if SimpleCov.method_coverage?
  result
end