Class: Rbs::Merge::FreezeNode

Inherits:
Ast::Merge::FreezeNodeBase
  • Object
show all
Defined in:
lib/rbs/merge/freeze_node.rb

Overview

Wrapper to represent freeze blocks as first-class nodes in RBS files. 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 RBS type signature files.

Examples:

Freeze block in RBS

# rbs-merge:freeze
# Custom type definitions
type custom_config = { key: String, value: untyped }
# rbs-merge:unfreeze

Freeze block with reason

# rbs-merge:freeze Project-specific types
type project_result = success | failure
# rbs-merge:unfreeze

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

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.

Parameters:

  • start_line (Integer)

    Line number of freeze marker

  • end_line (Integer)

    Line number of unfreeze marker

  • analysis (FileAnalysis)

    The file analysis containing this block

  • nodes (Array<RBS::AST::Declarations::Base, RBS::AST::Members::Base>) (defaults to: [])

    Nodes fully contained within the freeze block

  • overlapping_nodes (Array) (defaults to: nil)

    All nodes that overlap with freeze block (for validation)

  • start_marker (String, nil) (defaults to: nil)

    The freeze start marker text

  • end_marker (String, nil) (defaults to: nil)

    The freeze end marker text

  • pattern_type (Symbol) (defaults to: Ast::Merge::FreezeNodeBase::DEFAULT_PATTERN)

    Pattern type for marker matching (defaults to :hash_comment)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rbs/merge/freeze_node.rb', line 39

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

#inspectString

String representation for debugging

Returns:

  • (String)


68
69
70
# File 'lib/rbs/merge/freeze_node.rb', line 68

def inspect
  "#<Rbs::Merge::FreezeNode lines=#{@start_line}..#{@end_line} nodes=#{@nodes.length}>"
end

#signatureArray

Returns a stable signature for this freeze block Signature includes the normalized content to detect changes

Returns:

  • (Array)

    Signature array



58
59
60
61
62
63
64
# File 'lib/rbs/merge/freeze_node.rb', line 58

def signature
  normalized = (@start_line..@end_line).map do |ln|
    @analysis.normalized_line(ln)
  end.compact.join("\n")

  [:FreezeNode, normalized]
end