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. Nocov nodes preserve source locations and marker text as one structural unit; the initializer mirrors the node's complete serialized shape. rubocop:disable Metrics/CyclomaticComplexity, Metrics/ParameterLists, Metrics/PerceivedComplexity

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.



26
27
28
29
30
31
32
33
# File 'lib/ruby/merge/nocov_node_base.rb', line 26

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.



24
25
26
# File 'lib/ruby/merge/nocov_node_base.rb', line 24

def analysis
  @analysis
end

#close_markerObject (readonly)

Returns the value of attribute close_marker.



24
25
26
# File 'lib/ruby/merge/nocov_node_base.rb', line 24

def close_marker
  @close_marker
end

#end_lineObject (readonly)

Returns the value of attribute end_line.



24
25
26
# File 'lib/ruby/merge/nocov_node_base.rb', line 24

def end_line
  @end_line
end

#nodesObject (readonly)

Returns the value of attribute nodes.



24
25
26
# File 'lib/ruby/merge/nocov_node_base.rb', line 24

def nodes
  @nodes
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



24
25
26
# File 'lib/ruby/merge/nocov_node_base.rb', line 24

def start_line
  @start_line
end

#start_markerObject (readonly)

Returns the value of attribute start_marker.



24
25
26
# File 'lib/ruby/merge/nocov_node_base.rb', line 24

def start_marker
  @start_marker
end

Instance Method Details

#childrenObject



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

def children = @nodes

#inspectObject Also known as: to_s



71
72
73
# File 'lib/ruby/merge/nocov_node_base.rb', line 71

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

#kindObject



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

def kind = :nocov

#locationObject



41
42
43
# File 'lib/ruby/merge/nocov_node_base.rb', line 41

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

#merge_policyObject



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

def merge_policy = nil

#merge_typeObject Also known as: type



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

def merge_type = :nocov_block

#nocov_node?Boolean

Returns:

  • (Boolean)


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

def nocov_node? = true

#signatureObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/ruby/merge/nocov_node_base.rb', line 54

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



45
46
47
48
49
50
51
52
# File 'lib/ruby/merge/nocov_node_base.rb', line 45

def slice
  return unless @analysis

  lines = @analysis.lines
  return unless lines

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