Class: Json::Merge::FreezeNode

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

Overview

Wrapper to represent comment-marked freeze blocks as first-class nodes in JSON / JSONC files.

Constant Summary collapse

InvalidStructureError =
Ast::Merge::FreezeNodeBase::InvalidStructureError
Location =
Ast::Merge::FreezeNodeBase::Location

Instance Method Summary collapse

Constructor Details

#initialize(start_line:, end_line:, lines:, start_marker: nil, end_marker: nil, pattern_type: :c_style_line) ⇒ FreezeNode

Returns a new instance of FreezeNode.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/json/merge/freeze_node.rb', line 11

def initialize(start_line:, end_line:, lines:, start_marker: nil, end_marker: nil, pattern_type: :c_style_line)
  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

#array?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/json/merge/freeze_node.rb', line 35

def array?
  false
end

#inspectObject



43
44
45
# File 'lib/json/merge/freeze_node.rb', line 43

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

#object?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/json/merge/freeze_node.rb', line 31

def object?
  false
end

#pair?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/json/merge/freeze_node.rb', line 39

def pair?
  false
end

#signatureObject



26
27
28
29
# File 'lib/json/merge/freeze_node.rb', line 26

def signature
  normalized = @lines.map { |line| line&.strip }.compact.reject(&:empty?).join("\n")
  [:FreezeNode, normalized]
end