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.
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.
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
#analysis ⇒ Object (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_marker ⇒ Object (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_line ⇒ Object (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 |
#nodes ⇒ Object (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_line ⇒ Object (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_marker ⇒ Object (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
#children ⇒ Object
34 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 34 def children = @nodes |
#inspect ⇒ Object 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 |
#kind ⇒ Object
32 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 32 def kind = :nocov |
#location ⇒ Object
38 39 40 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 38 def location @location ||= Location.new(@start_line, @end_line) end |
#merge_policy ⇒ Object
36 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 36 def merge_policy = nil |
#merge_type ⇒ Object Also known as: type
62 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 62 def merge_type = :nocov_block |
#nocov_node? ⇒ Boolean
66 |
# File 'lib/ruby/merge/nocov_node_base.rb', line 66 def nocov_node? = true |
#signature ⇒ Object
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 |
#slice ⇒ Object
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 |