Class: Ast::Merge::Comment::TrackedHashAdapter
- Inherits:
-
Object
- Object
- Ast::Merge::Comment::TrackedHashAdapter
- Defined in:
- lib/ast/merge/comment/tracked_hash_adapter.rb
Overview
Converts producer-specific tracked comment hashes into standardized Ast::Merge::Comment nodes and regions.
This adapter is intentionally conservative. It currently targets the line-comment hash shape used by source trackers such as psych-merge's CommentTracker:
{
line: 12,
indent: 2,
text: "Example comment",
full_line: true,
raw: " # Example comment"
}
The adapter does not infer ownership by itself. Callers provide region kinds explicitly and can preserve original producer facts via metadata.
Class Method Summary collapse
-
.node(comment_hash = nil, style: nil, **options) ⇒ Comment::Line
Convert a tracked comment hash into a normalized shared comment node.
-
.region(kind:, comments:, style: nil, metadata: {}, **options) ⇒ Region
Convert tracked comment hashes into a normalized shared comment region.
Class Method Details
.node(comment_hash = nil, style: nil, **options) ⇒ Comment::Line
Convert a tracked comment hash into a normalized shared comment node.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ast/merge/comment/tracked_hash_adapter.rb', line 31 def node(comment_hash = nil, style: nil, **) hash = normalize_hash(comment_hash || ) style = resolve_style(style) validate_style!(style) validate_hash!(hash) Comment::Line.new( text: line_text_from(hash, style), line_number: hash.fetch(:line), style: style ) end |
.region(kind:, comments:, style: nil, metadata: {}, **options) ⇒ Region
Convert tracked comment hashes into a normalized shared comment region.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ast/merge/comment/tracked_hash_adapter.rb', line 52 def region(kind:, comments:, style: nil, metadata: {}, **) normalized = Array(comments).map { |comment_hash| normalize_hash(comment_hash) } nodes = normalized.map { |comment_hash| node(comment_hash, style: style) } Region.new( kind: kind, nodes: nodes, metadata: .merge( source: :tracked_hash, tracked_hashes: normalized ).merge() ) end |