Class: Ruby::Merge::NocovNodeBase
- Inherits:
-
Object
- Object
- Ruby::Merge::NocovNodeBase
- 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
-
#analysis ⇒ Object
readonly
Returns the value of attribute analysis.
-
#close_marker ⇒ Object
readonly
Returns the value of attribute close_marker.
-
#end_line ⇒ Object
readonly
Returns the value of attribute end_line.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#start_line ⇒ Object
readonly
Returns the value of attribute start_line.
-
#start_marker ⇒ Object
readonly
Returns the value of attribute start_marker.
Instance Method Summary collapse
- #children ⇒ Object
-
#initialize(start_line:, end_line:, analysis:, nodes: [], start_marker: nil, close_marker: nil) ⇒ NocovNodeBase
constructor
A new instance of NocovNodeBase.
- #inspect ⇒ Object (also: #to_s)
- #kind ⇒ Object
- #location ⇒ Object
- #merge_policy ⇒ Object
- #merge_type ⇒ Object (also: #type)
- #nocov_node? ⇒ Boolean
- #signature ⇒ Object
- #slice ⇒ Object
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
#analysis ⇒ Object (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_marker ⇒ Object (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_line ⇒ Object (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 |
#nodes ⇒ Object (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_line ⇒ Object (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_marker ⇒ Object (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
#children ⇒ Object
37 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 37 def children = @nodes |
#inspect ⇒ Object 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 |
#kind ⇒ Object
35 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 35 def kind = :nocov |
#location ⇒ Object
41 42 43 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 41 def location @location ||= Location.new(@start_line, @end_line) end |
#merge_policy ⇒ Object
39 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 39 def merge_policy = nil |
#merge_type ⇒ Object Also known as: type
65 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 65 def merge_type = :nocov_block |
#nocov_node? ⇒ Boolean
69 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 69 def nocov_node? = true |
#signature ⇒ Object
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 |
#slice ⇒ Object
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 |