Class: Dotenv::Merge::CommentTracker

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

Overview

Extracts and tracks dotenv comments with their line numbers from source.

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.

Dotenv supports hash-style comments as either:

  • full-line comments (# comment)
  • safe inline comments on unquoted assignments (KEY=value # comment)

This adapter intentionally stays conservative around quoted values. # inside quoted values is not treated as a comment, and quoted assignments with trailing comment-like text remain literal value content. That is a deliberate parser boundary for dotenv-merge, not a pending comment-matrix bug to "fix" later without an explicit product decision.

Instance Method Summary collapse

Constructor Details

#initialize(source_or_lines) ⇒ CommentTracker

Returns a new instance of CommentTracker.



21
22
23
24
25
# File 'lib/dotenv/merge/comment_tracker.rb', line 21

def initialize(source_or_lines)
  @line_objects = normalize_line_objects(source_or_lines)
  @line_parser = Ast::Merge::Comment::QuotedHashLineParser.new
  super(@line_objects.map(&:raw))
end

Instance Method Details

#augment(owners: [], **options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dotenv/merge/comment_tracker.rb', line 27

def augment(owners: [], **options)
  Ast::Merge::Comment::Augmenter.new(
    lines: @lines,
    comments: @comments,
    owners: owners,
    style: :hash_comment,
    total_comment_count: @comments.size,
    inline_comment_count: @comments.count { |comment| !comment[:full_line] },
    **options
  )
end