Class: Cyclid::API::Plugins::Simplecov

Inherits:
Action
  • Object
show all
Defined in:
app/cyclid/plugins/action/simplecov.rb

Overview

Simplecov coverage reader plugin

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Action

human_name, #prepare

Methods inherited from Base

author, config?, config_schema, default_config, get_config, homepage, human_name, license, register_plugin, set_config, update_config, version

Constructor Details

#initialize(args = {}) ⇒ Simplecov

Returns a new instance of Simplecov.



24
25
26
27
28
29
30
31
# File 'app/cyclid/plugins/action/simplecov.rb', line 24

def initialize(args = {})
  args.symbolize_keys!

  # There must be the path to the coverage report..
  raise 'a simplecov action requires a path' unless args.include? :path

  @path = args[:path]
end

Class Method Details

.metadataObject

Plugin metadata



55
56
57
58
59
60
# File 'app/cyclid/plugins/action/simplecov.rb', line 55

def self.
  super.merge!(version: Cyclid::Api::VERSION,
               license: 'Apache-2.0',
               author: 'Liqwyd Ltd.',
               homepage: 'http://docs.cyclid.io')
end

Instance Method Details

#perform(log) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/cyclid/plugins/action/simplecov.rb', line 33

def perform(log)
  # Retrieve the Simplecov JSON report
  report = StringIO.new
  @transport.download(report, @path ** @ctx)

  # Parse the report and extract the total coverage percentage;
  # Simplecov can produce oddly specific coverage metrics, so round it
  # to only 2 decimal points...
  coverage = JSON.parse(report.string)
  covered_percent = coverage['metrics']['covered_percent'].round(2)

  log.write "Simplecov coverage is #{covered_percent}%\n"
  @ctx[:simplecov_coverage] = "#{covered_percent}%"

  return [true, 0]
rescue StandardError => ex
  log.write "Failed to read Simplecov coverage report: #{ex}"

  return [false, 0]
end