Class: SimpleCov::SourceFile::Method
- Inherits:
-
Object
- Object
- SimpleCov::SourceFile::Method
- Defined in:
- lib/simplecov/source_file/method.rb
Overview
Represents a single method detected in coverage data. Provides helpers similar to Branch for coverage status.
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#coverage ⇒ Object
readonly
Returns the value of attribute coverage.
-
#end_col ⇒ Object
readonly
Returns the value of attribute end_col.
-
#end_line ⇒ Object
readonly
Returns the value of attribute end_line.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
-
#start_col ⇒ Object
readonly
Returns the value of attribute start_col.
-
#start_line ⇒ Object
readonly
Returns the value of attribute start_line.
Instance Method Summary collapse
- #covered? ⇒ Boolean
-
#initialize(source_file, info, coverage) ⇒ Method
constructor
A new instance of Method.
- #lines ⇒ Object
- #missed? ⇒ Boolean
-
#overlaps_with?(line_range) ⇒ Boolean
Whether this method’s source range intersects the given inclusive line range.
-
#skipped! ⇒ Object
Flag the method as skipped directly, without going through its lines.
- #skipped? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(source_file, info, coverage) ⇒ Method
Returns a new instance of Method.
11 12 13 14 15 |
# File 'lib/simplecov/source_file/method.rb', line 11 def initialize(source_file, info, coverage) @source_file = source_file @class_name, @method_name, @start_line, @start_col, @end_line, @end_col = info @coverage = coverage end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
8 9 10 |
# File 'lib/simplecov/source_file/method.rb', line 8 def class_name @class_name end |
#coverage ⇒ Object (readonly)
Returns the value of attribute coverage.
8 9 10 |
# File 'lib/simplecov/source_file/method.rb', line 8 def coverage @coverage end |
#end_col ⇒ Object (readonly)
Returns the value of attribute end_col.
8 9 10 |
# File 'lib/simplecov/source_file/method.rb', line 8 def end_col @end_col end |
#end_line ⇒ Object (readonly)
Returns the value of attribute end_line.
8 9 10 |
# File 'lib/simplecov/source_file/method.rb', line 8 def end_line @end_line end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
8 9 10 |
# File 'lib/simplecov/source_file/method.rb', line 8 def method_name @method_name end |
#source_file ⇒ Object (readonly)
Returns the value of attribute source_file.
8 9 10 |
# File 'lib/simplecov/source_file/method.rb', line 8 def source_file @source_file end |
#start_col ⇒ Object (readonly)
Returns the value of attribute start_col.
8 9 10 |
# File 'lib/simplecov/source_file/method.rb', line 8 def start_col @start_col end |
#start_line ⇒ Object (readonly)
Returns the value of attribute start_line.
8 9 10 |
# File 'lib/simplecov/source_file/method.rb', line 8 def start_line @start_line end |
Instance Method Details
#covered? ⇒ Boolean
17 18 19 |
# File 'lib/simplecov/source_file/method.rb', line 17 def covered? !skipped? && coverage.positive? end |
#lines ⇒ Object
36 37 38 |
# File 'lib/simplecov/source_file/method.rb', line 36 def lines @lines ||= start_line && end_line ? source_file.lines[(start_line - 1)..(end_line - 1)] : [] end |
#missed? ⇒ Boolean
32 33 34 |
# File 'lib/simplecov/source_file/method.rb', line 32 def missed? !skipped? && coverage.zero? end |
#overlaps_with?(line_range) ⇒ Boolean
Whether this method’s source range intersects the given inclusive line range.
41 42 43 44 45 |
# File 'lib/simplecov/source_file/method.rb', line 41 def overlaps_with?(line_range) return false unless start_line && end_line start_line <= line_range.end && end_line >= line_range.begin end |
#skipped! ⇒ Object
Flag the method as skipped directly, without going through its lines.
28 29 30 |
# File 'lib/simplecov/source_file/method.rb', line 28 def skipped! @skipped = true end |
#skipped? ⇒ Boolean
21 22 23 24 25 |
# File 'lib/simplecov/source_file/method.rb', line 21 def skipped? return @skipped if defined?(@skipped) @skipped = lines.all?(&:skipped?) end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/simplecov/source_file/method.rb', line 47 def to_s "#{class_name}##{method_name}" end |