Class: Prism::Merge::FreezeNode
- Inherits:
-
Ast::Merge::FreezeNodeBase
- Object
- Ast::Merge::FreezeNodeBase
- Prism::Merge::FreezeNode
- Defined in:
- lib/prism/merge/freeze_node.rb
Overview
Wrapper to represent freeze blocks as first-class nodes.
A freeze block is a section marked with freeze/unfreeze comment markers that
should be preserved from the destination during merges.
Inherits from Ast::Merge::FreezeNodeBase for shared functionality including
the Location struct, InvalidStructureError, and configurable marker patterns.
Uses the :hash_comment pattern type by default for Ruby source files.
While freeze blocks are delineated by comment markers, they are conceptually
different from CommentNode and do not inherit from it because:
- FreezeNodeBase is a structural directive that contains code and/or comments
- CommentNode represents pure documentation with no structural significance
- FreezeNodeBase can contain Ruby code nodes (methods, constants, etc.)
- CommentNode only contains comments
- Their signatures need different semantics for merge matching
Freeze blocks can contain other nodes (methods, classes, etc.) and those
nodes remain as separate entities within the block for analysis purposes,
but the entire freeze block is treated as an atomic unit during merging.
Constant Summary collapse
- InvalidStructureError =
Inherit InvalidStructureError from base class
Ast::Merge::FreezeNodeBase::InvalidStructureError
- Location =
Inherit Location from base class
Ast::Merge::FreezeNodeBase::Location
Instance Method Summary collapse
-
#initialize(start_line:, end_line:, analysis:, nodes: [], overlapping_nodes: nil, start_marker: nil, end_marker: nil, pattern_type: Ast::Merge::FreezeNodeBase::DEFAULT_PATTERN) ⇒ FreezeNode
constructor
A new instance of FreezeNode.
-
#inspect ⇒ String
String representation for debugging.
-
#signature ⇒ Array
Returns a stable signature for this freeze block Signature includes the normalized content to detect changes.
Constructor Details
#initialize(start_line:, end_line:, analysis:, nodes: [], overlapping_nodes: nil, start_marker: nil, end_marker: nil, pattern_type: Ast::Merge::FreezeNodeBase::DEFAULT_PATTERN) ⇒ FreezeNode
Returns a new instance of FreezeNode.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/prism/merge/freeze_node.rb', line 49 def initialize(start_line:, end_line:, analysis:, nodes: [], overlapping_nodes: nil, start_marker: nil, end_marker: nil, pattern_type: Ast::Merge::FreezeNodeBase::DEFAULT_PATTERN) super( start_line: start_line, end_line: end_line, analysis: analysis, nodes: nodes, overlapping_nodes: overlapping_nodes || nodes, start_marker: start_marker, end_marker: end_marker, pattern_type: pattern_type ) # Validate structure validate_structure! end |
Instance Method Details
#inspect ⇒ String
String representation for debugging
78 79 80 |
# File 'lib/prism/merge/freeze_node.rb', line 78 def inspect "#<Prism::Merge::FreezeNode lines=#{@start_line}..#{@end_line} nodes=#{@nodes.length}>" end |
#signature ⇒ Array
Returns a stable signature for this freeze block
Signature includes the normalized content to detect changes
68 69 70 71 72 73 74 |
# File 'lib/prism/merge/freeze_node.rb', line 68 def signature normalized = (@start_line..@end_line).map do |ln| @analysis.normalized_line(ln) end.compact.join("\n") [:FreezeNode, normalized] end |