Class: OpenapiContracts::Coverage::Report
- Inherits:
-
Object
- Object
- OpenapiContracts::Coverage::Report
- Defined in:
- lib/openapi_contracts/coverage/report.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #generate(pathname) ⇒ Object
-
#initialize(doc, data = {}) ⇒ Report
constructor
A new instance of Report.
- #merge!(data) ⇒ Object
- #meta ⇒ Object
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
#data ⇒ Object (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
Instance Method Details
#as_json ⇒ Object
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 |
#meta ⇒ Object
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 { '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 |