Class: SimcovAiFormatter::SimpleCovFormatter
- Inherits:
-
Object
- Object
- SimcovAiFormatter::SimpleCovFormatter
- Defined in:
- lib/simcov_ai_formatter/simple_cov_formatter.rb
Overview
SimpleCov plugin formatter — emits the AI-friendly JSON during a SimpleCov run, without requiring a separate ‘simcov-ai-formatter` invocation.
Usage:
require "simcov_ai_formatter/simple_cov_formatter"
SimpleCov.formatter = SimcovAiFormatter::SimpleCovFormatter
# or alongside other formatters:
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.create([
SimpleCov::Formatter::HTMLFormatter,
SimcovAiFormatter::SimpleCovFormatter
])
Configure (before SimpleCov.start):
SimcovAiFormatter::SimpleCovFormatter.with_source = true
SimcovAiFormatter::SimpleCovFormatter.context = 3
SimcovAiFormatter::SimpleCovFormatter.pretty = true
SimcovAiFormatter::SimpleCovFormatter.output_path = "tmp/coverage.ai.json"
Constant Summary collapse
- DEFAULT_OUTPUT_FILENAME =
".resultset.ai.json".freeze
Class Attribute Summary collapse
-
.context ⇒ Object
Returns the value of attribute context.
-
.output_path ⇒ Object
Returns the value of attribute output_path.
-
.pretty ⇒ Object
Returns the value of attribute pretty.
-
.with_source ⇒ Object
Returns the value of attribute with_source.
Instance Method Summary collapse
-
#format(result) ⇒ Object
SimpleCov calls this with a SimpleCov::Result instance.
Class Attribute Details
.context ⇒ Object
Returns the value of attribute context.
27 28 29 |
# File 'lib/simcov_ai_formatter/simple_cov_formatter.rb', line 27 def context @context end |
.output_path ⇒ Object
Returns the value of attribute output_path.
27 28 29 |
# File 'lib/simcov_ai_formatter/simple_cov_formatter.rb', line 27 def output_path @output_path end |
.pretty ⇒ Object
Returns the value of attribute pretty.
27 28 29 |
# File 'lib/simcov_ai_formatter/simple_cov_formatter.rb', line 27 def pretty @pretty end |
.with_source ⇒ Object
Returns the value of attribute with_source.
27 28 29 |
# File 'lib/simcov_ai_formatter/simple_cov_formatter.rb', line 27 def with_source @with_source end |
Instance Method Details
#format(result) ⇒ Object
SimpleCov calls this with a SimpleCov::Result instance.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/simcov_ai_formatter/simple_cov_formatter.rb', line 35 def format(result) with_source = self.class.with_source context = self.class.context pretty = self.class.pretty raw = result.to_hash selected_suite, coverage = SuiteMerger.new(raw).select source_reader = with_source ? SourceReader.new(warnings: $stderr) : nil formatted = Formatter.new( coverage: coverage, suite: selected_suite, suites_merged: nil, root: simplecov_root, with_source: with_source, context: context, source_reader: source_reader ).call json = Renderer.new(pretty: pretty).render(formatted) target = resolve_output_path File.write(target, json + "\n") source_reader&.report_missing puts "Coverage AI report generated to #{target}" target end |