Class: Bash::Merge::FreezeNode

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

Overview

Wrapper to represent freeze blocks as first-class nodes in Bash scripts. 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 Bash files (# comments).

Examples:

Freeze block in Bash

# bash-merge:freeze
SECRET_KEY="my-secret-value"
API_ENDPOINT="https://custom.example.com"
# bash-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)



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

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

#command?Boolean

Check if this is a command (always false for FreezeNode)

Returns:

  • (Boolean)


71
72
73
# File 'lib/bash/merge/freeze_node.rb', line 71

def command?
  false
end

#function_definition?Boolean

Check if this is a function definition (always false for FreezeNode)

Returns:

  • (Boolean)


59
60
61
# File 'lib/bash/merge/freeze_node.rb', line 59

def function_definition?
  false
end

#inspectString

String representation for debugging

Returns:

  • (String)


77
78
79
80
81
82
83
84
# File 'lib/bash/merge/freeze_node.rb', line 77

def inspect
  # simplecov:disable
  # Defensive: slice is always set via resolve_content in FreezeNodeBase#initialize
  # The || 0 branch is normally unreachable because validate_structure! ensures non-empty content
  content_length = slice&.length || 0
  # simplecov:enable
  "#<#{self.class.name} lines=#{start_line}..#{end_line} content_length=#{content_length}>"
end

#signatureArray

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

Returns:

  • (Array)

    Signature array



51
52
53
54
55
# File 'lib/bash/merge/freeze_node.rb', line 51

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

#variable_assignment?Boolean

Check if this is a variable assignment (always false for FreezeNode)

Returns:

  • (Boolean)


65
66
67
# File 'lib/bash/merge/freeze_node.rb', line 65

def variable_assignment?
  false
end