Class: OpenapiContracts::Coverage::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_contracts/coverage/report.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, data = {}) ⇒ Report

Returns a new instance of Report.



15
16
17
18
# File 'lib/openapi_contracts/coverage/report.rb', line 15

def initialize(doc, data = {})
  @doc = doc
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/openapi_contracts/coverage/report.rb', line 9

def data
  @data
end

Class Method Details

.merge(doc, *reports) ⇒ Object



3
4
5
6
7
# File 'lib/openapi_contracts/coverage/report.rb', line 3

def self.merge(doc, *reports)
  reports.each_with_object(Report.new(doc)) do |r, m|
    m.merge!(r)
  end
end

Instance Method Details

#as_jsonObject



11
12
13
# File 'lib/openapi_contracts/coverage/report.rb', line 11

def as_json(*)
  report
end

#generate(pathname) ⇒ Object



20
21
22
# File 'lib/openapi_contracts/coverage/report.rb', line 20

def generate(pathname)
  File.write(pathname, JSON.pretty_generate(report))
end

#merge!(data) ⇒ Object



24
25
26
# File 'lib/openapi_contracts/coverage/report.rb', line 24

def merge!(data)
  @data.deep_merge!(data) { |_key, val1, val2| val1 + val2 }
end

#metaObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/openapi_contracts/coverage/report.rb', line 28

def meta
  {
    'operations' => {
      'covered' => total_covered_operations,
      'total'   => @doc.operations.count
    },
    'responses'  => {
      'covered' => total_covered_responses,
      'total'   => @doc.responses.count
    }
  }.tap do |d|
    d['operations']['quota'] = d['operations']['covered'].to_f / d['operations']['total']
    d['responses']['quota'] = d['responses']['covered'].to_f / d['responses']['total']
  end
end