Class: ElasticResults::SimpleCov::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_results/simplecov.rb

Overview

A simple formatter that converts a SimpleCov Result to a hash to be stored in elastic search

Instance Method Summary collapse

Instance Method Details

#format(result) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/elastic_results/simplecov.rb', line 8

def format(result)
  data = base_info

  data[:command_name] = result.command_name
  data[:metrics] = {
    covered_percent: result.covered_percent,
    covered_strength: result.covered_strength.nan? ? 0.0 : result.covered_strength,
    covered_lines: result.covered_lines,
    total_lines: result.total_lines
  }

  ElasticResults.with_disabled_mocks {
    if ElasticResults.use_unsafe_index
      ElasticResults.unsafe_index ElasticResults.es_index_coverage, ElasticResults.es_type_coverage, data
    else
      ElasticResults.client.index index: ElasticResults.es_index_coverage, type: ElasticResults.es_type_coverage, body: data
    end
  }
end