Class: Undercover::SimplecovResultAdapter
- Inherits:
-
Object
- Object
- Undercover::SimplecovResultAdapter
- Includes:
- RootToRelativePaths
- Defined in:
- lib/undercover/simplecov_result_adapter.rb
Instance Attribute Summary collapse
-
#simplecov_result ⇒ Object
readonly
Returns the value of attribute simplecov_result.
Class Method Summary collapse
-
.parse(file, opts = nil) ⇒ Object
SimplecovResultAdapter.
Instance Method Summary collapse
-
#coverage(filepath) ⇒ Object
Array tuples (lines) and quadruples (branches) compatible with LcovParser.
- #ignored_files ⇒ Object
-
#initialize(simplecov_result, opts) ⇒ SimplecovResultAdapter
constructor
A new instance of SimplecovResultAdapter.
- #skipped?(filepath, line_no) ⇒ Boolean
- #total_branch_coverage ⇒ Object
-
#total_coverage ⇒ Object
unused for now.
Methods included from RootToRelativePaths
Constructor Details
#initialize(simplecov_result, opts) ⇒ SimplecovResultAdapter
Returns a new instance of SimplecovResultAdapter.
23 24 25 26 |
# File 'lib/undercover/simplecov_result_adapter.rb', line 23 def initialize(simplecov_result, opts) @simplecov_result = simplecov_result @code_dir = opts&.path end |
Instance Attribute Details
#simplecov_result ⇒ Object (readonly)
Returns the value of attribute simplecov_result.
9 10 11 |
# File 'lib/undercover/simplecov_result_adapter.rb', line 9 def simplecov_result @simplecov_result end |
Class Method Details
.parse(file, opts = nil) ⇒ Object
Returns SimplecovResultAdapter.
13 14 15 16 17 18 19 20 |
# File 'lib/undercover/simplecov_result_adapter.rb', line 13 def self.parse(file, opts = nil) # :nocov: result_h = JSON.parse(file.read) raise ArgumentError, 'empty SimpleCov' if result_h.empty? new(result_h, opts) # :nocov: end |
Instance Method Details
#coverage(filepath) ⇒ Object
Returns Array tuples (lines) and quadruples (branches) compatible with LcovParser.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/undercover/simplecov_result_adapter.rb', line 30 def coverage(filepath) # rubocop:disable Metrics/MethodLength source_file = find_file(filepath) return [] unless source_file lines = source_file['lines'].map.with_index do |line_coverage, idx| [idx + 1, line_coverage] if line_coverage end.compact return lines unless source_file['branches'] branch_idx = 0 branches = source_file['branches'].map do |branch| branch_idx += 1 [branch['start_line'], 0, branch_idx, branch['coverage']] end lines + branches end |
#ignored_files ⇒ Object
59 60 61 |
# File 'lib/undercover/simplecov_result_adapter.rb', line 59 def ignored_files @ignored_files ||= simplecov_result.dig('meta', 'ignored_files') || [] end |
#skipped?(filepath, line_no) ⇒ Boolean
48 49 50 51 52 53 |
# File 'lib/undercover/simplecov_result_adapter.rb', line 48 def skipped?(filepath, line_no) source_file = find_file(filepath) return false unless source_file source_file['lines'][line_no - 1] == 'ignored' end |
#total_branch_coverage ⇒ Object
57 |
# File 'lib/undercover/simplecov_result_adapter.rb', line 57 def total_branch_coverage; end |
#total_coverage ⇒ Object
unused for now
56 |
# File 'lib/undercover/simplecov_result_adapter.rb', line 56 def total_coverage; end |