Class: Ruby::Merge::NocovNodeBase

Inherits:
Object
  • Object
show all
Includes:
Ast::Merge::BlockDirective
Defined in:
lib/ruby/merge/nocov_node_base.rb

Overview

Shared Ruby synthetic node for a balanced coverage-exclusion block.

Parser-specific merge gems subclass this when they need native AST location or comment attachment behavior. The structural Ruby semantics live here: nocov blocks follow file preference and match by their inner content.

Defined Under Namespace

Classes: Location

Constant Summary collapse

InvalidStructureError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_line:, end_line:, analysis:, nodes: [], start_marker: nil, close_marker: nil) ⇒ NocovNodeBase

Returns a new instance of NocovNodeBase.



23
24
25
26
27
28
29
30
# File 'lib/ruby/merge/nocov_node_base.rb', line 23

def initialize(start_line:, end_line:, analysis:, nodes: [], start_marker: nil, close_marker: nil)
  @start_line = start_line
  @end_line = end_line
  @analysis = analysis
  @nodes = nodes
  @start_marker = start_marker
  @close_marker = close_marker
end

Instance Attribute Details

#analysisObject (readonly)

Returns the value of attribute analysis.



21
22
23
# File 'lib/ruby/merge/nocov_node_base.rb', line 21

def analysis
  @analysis
end

#close_markerObject (readonly)

Returns the value of attribute close_marker.



21
22
23
# File 'lib/ruby/merge/nocov_node_base.rb', line 21

def close_marker
  @close_marker
end

#end_lineObject (readonly)

Returns the value of attribute end_line.



21
22
23
# File 'lib/ruby/merge/nocov_node_base.rb', line 21

def end_line
  @end_line
end

#nodesObject (readonly)

Returns the value of attribute nodes.



21
22
23
# File 'lib/ruby/merge/nocov_node_base.rb', line 21

def nodes
  @nodes
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



21
22
23
# File 'lib/ruby/merge/nocov_node_base.rb', line 21

def start_line
  @start_line
end

#start_markerObject (readonly)

Returns the value of attribute start_marker.



21
22
23
# File 'lib/ruby/merge/nocov_node_base.rb', line 21

def start_marker
  @start_marker
end

Instance Method Details

#childrenObject



34
# File 'lib/ruby/merge/nocov_node_base.rb', line 34

def children = @nodes

#inspectObject Also known as: to_s



68
69
70
# File 'lib/ruby/merge/nocov_node_base.rb', line 68

def inspect
  "#<#{self.class} lines=#{@start_line}..#{@end_line} nodes=#{@nodes.length}>"
end

#kindObject



32
# File 'lib/ruby/merge/nocov_node_base.rb', line 32

def kind = :nocov

#locationObject



38
39
40
# File 'lib/ruby/merge/nocov_node_base.rb', line 38

def location
  @location ||= Location.new(@start_line, @end_line)
end

#merge_policyObject



36
# File 'lib/ruby/merge/nocov_node_base.rb', line 36

def merge_policy = nil

#merge_typeObject Also known as: type



62
# File 'lib/ruby/merge/nocov_node_base.rb', line 62

def merge_type = :nocov_block

#nocov_node?Boolean

Returns:

  • (Boolean)


66
# File 'lib/ruby/merge/nocov_node_base.rb', line 66

def nocov_node? = true

#signatureObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/ruby/merge/nocov_node_base.rb', line 51

def signature
  return [:NocovNode, nil] if @nodes.empty? || @analysis.nil?

  if @nodes.length == 1
    @analysis.generate_signature(@nodes.first)
  else
    inner_lines = @analysis.lines && @analysis.lines[@start_line..(@end_line - 2)]
    [:nocov_multi, inner_lines&.map(&:strip)&.join("\n")]
  end
end

#sliceObject



42
43
44
45
46
47
48
49
# File 'lib/ruby/merge/nocov_node_base.rb', line 42

def slice
  return unless @analysis

  lines = @analysis.lines
  return unless lines

  lines[(@start_line - 1)..(@end_line - 1)]&.join
end