Class: Psych::Merge::FreezeNode

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

Overview

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

Examples:

Freeze block in YAML

# psych-merge:freeze
custom_settings:
  secret_key: "my-secret-value"
  api_endpoint: "https://custom.example.com"
# psych-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:, lines:, 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

  • lines (Array<String>)

    All source lines

  • 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)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/psych/merge/freeze_node.rb', line 33

def initialize(start_line:, end_line:, lines:, start_marker: nil, end_marker: nil, pattern_type: Ast::Merge::FreezeNodeBase::DEFAULT_PATTERN)
  # Extract lines for the entire block (lines param is all source lines)
  block_lines = (start_line..end_line).map { |ln| lines[ln - 1] }

  super(
    start_line: start_line,
    end_line: end_line,
    lines: block_lines,
    start_marker: start_marker,
    end_marker: end_marker,
    pattern_type: pattern_type
  )

  validate_structure!
end

Instance Method Details

#inspectString

String representation for debugging

Returns:

  • (String)


78
79
80
# File 'lib/psych/merge/freeze_node.rb', line 78

def inspect
  "#<#{self.class.name} lines=#{start_line}..#{end_line} content_length=#{slice&.length || 0}>"
end

#mapping?Boolean

Check if this is a mapping node (always false for FreezeNode)

Returns:

  • (Boolean)


60
61
62
# File 'lib/psych/merge/freeze_node.rb', line 60

def mapping?
  false
end

#scalar?Boolean

Check if this is a scalar node (always false for FreezeNode)

Returns:

  • (Boolean)


72
73
74
# File 'lib/psych/merge/freeze_node.rb', line 72

def scalar?
  false
end

#sequence?Boolean

Check if this is a sequence node (always false for FreezeNode)

Returns:

  • (Boolean)


66
67
68
# File 'lib/psych/merge/freeze_node.rb', line 66

def sequence?
  false
end

#signatureArray

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

Returns:

  • (Array)

    Signature array



52
53
54
55
56
# File 'lib/psych/merge/freeze_node.rb', line 52

def signature
  # Normalize by stripping each line and joining
  normalized = @lines.map { |l| l&.strip }.compact.reject(&:empty?).join("\n")
  [:FreezeNode, normalized]
end