Class: Psych::Merge::CommentTracker

Inherits:
Ast::Merge::Comment::HashTrackerBase
  • Object
show all
Defined in:
lib/psych/merge/comment_tracker.rb

Overview

Extracts and tracks comments with their line numbers from YAML source. YAML comments use the same # syntax as Ruby, making freeze block detection straightforward.

Inherits shared lookup, query, region-building, and attachment API from Ast::Merge::Comment::HashTrackerBase. Only format-specific comment extraction and owner resolution are overridden here.

Examples:

Basic usage

tracker = CommentTracker.new(yaml_source)
tracker.comments # => [{line: 1, indent: 0, text: "This is a comment"}]
tracker.comment_at(1) # => {line: 1, indent: 0, text: "This is a comment"}

Comment types

# Full-line comment
key: value # Inline comment

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ CommentTracker

Initialize comment tracker by scanning the source

Parameters:

  • source (String)

    YAML source code



25
26
27
28
29
# File 'lib/psych/merge/comment_tracker.rb', line 25

def initialize(source)
  @source = source
  @line_parser = Ast::Merge::Comment::QuotedHashLineParser.new
  super(source.lines.map(&:chomp))
end