Class: SolargraphTestCoverage::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph_test_coverage/branch.rb

Overview

Adapted from SimpleCov - Small class that turns branch coverage data into something easier to work with

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_line:, end_line:, coverage:, inline:, type:) ⇒ Branch

Returns a new instance of Branch.



21
22
23
24
25
26
27
# File 'lib/solargraph_test_coverage/branch.rb', line 21

def initialize(start_line:, end_line:, coverage:, inline:, type:)
  @start_line = start_line
  @end_line   = end_line
  @coverage   = coverage
  @inline     = inline
  @type       = type
end

Instance Attribute Details

#coverageObject (readonly)

Returns the value of attribute coverage.



19
20
21
# File 'lib/solargraph_test_coverage/branch.rb', line 19

def coverage
  @coverage
end

#end_lineObject (readonly)

Returns the value of attribute end_line.



19
20
21
# File 'lib/solargraph_test_coverage/branch.rb', line 19

def end_line
  @end_line
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



19
20
21
# File 'lib/solargraph_test_coverage/branch.rb', line 19

def start_line
  @start_line
end

#typeObject (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/solargraph_test_coverage/branch.rb', line 19

def type
  @type
end

Class Method Details

.build_from(results) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/solargraph_test_coverage/branch.rb', line 6

def self.build_from(results)
  results.fetch(:branches, {}).flat_map do |condition, branches|
    _condition_type, _condition_id, condition_start_line, * = condition

    branches.map do |branch_data, hit_count|
      type, _id, start_line, _start_col, end_line, _end_col = branch_data

      new(start_line: start_line, end_line: end_line, coverage: hit_count,
          inline: start_line == condition_start_line, type: type)
    end
  end
end

Instance Method Details

#covered?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/solargraph_test_coverage/branch.rb', line 33

def covered?
  coverage.positive?
end

#inline?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/solargraph_test_coverage/branch.rb', line 29

def inline?
  @inline
end

#reportObject



41
42
43
# File 'lib/solargraph_test_coverage/branch.rb', line 41

def report
  { type: type, line: report_line }
end

#report_lineObject



37
38
39
# File 'lib/solargraph_test_coverage/branch.rb', line 37

def report_line
  inline? ? start_line : start_line - 1
end