Class: Ast::Merge::Comment::Augmenter

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/comment/augmenter.rb

Overview

Builds standardized comment regions and attachments from source text, tracked comment hashes, and structural owner ranges.

This is a passive augmentation layer. It does not modify merge behavior; it only infers normalized Comment::Region and Comment::Attachment objects that format gems can adopt incrementally.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines: nil, source: nil, comments: [], owners: [], style: nil, capability: nil, **options) ⇒ Augmenter

Returns a new instance of Augmenter.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ast/merge/comment/augmenter.rb', line 33

def initialize(lines: nil, source: nil, comments: [], owners: [], style: nil, capability: nil, **options)
  @lines = normalize_lines(lines, source)
  @style = resolve_style(style)
  @owners = normalize_owners(owners)
  @tracked_comments = normalize_comments(comments)
  @capability = capability || Capability.source_augmented(
    source: :tracked_hash,
    style: style_name,
    owner_count: @owners.size,
    comment_count: @tracked_comments.size,
    **options
  )

  @attachments_by_owner = {}
  @preamble_region = nil
  @postlude_region = nil
  @orphan_regions = []

  build!
end

Instance Attribute Details

#attachments_by_ownerObject (readonly)

Returns the value of attribute attachments_by_owner.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def attachments_by_owner
  @attachments_by_owner
end

#capabilityObject (readonly)

Returns the value of attribute capability.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def capability
  @capability
end

#linesObject (readonly)

Returns the value of attribute lines.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def lines
  @lines
end

#orphan_regionsObject (readonly)

Returns the value of attribute orphan_regions.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def orphan_regions
  @orphan_regions
end

#ownersObject (readonly)

Returns the value of attribute owners.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def owners
  @owners
end

#postlude_regionObject (readonly)

Returns the value of attribute postlude_region.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def postlude_region
  @postlude_region
end

#preamble_regionObject (readonly)

Returns the value of attribute preamble_region.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def preamble_region
  @preamble_region
end

#styleObject (readonly)

Returns the value of attribute style.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def style
  @style
end

#tracked_commentsObject (readonly)

Returns the value of attribute tracked_comments.



13
14
15
# File 'lib/ast/merge/comment/augmenter.rb', line 13

def tracked_comments
  @tracked_comments
end

Class Method Details

.call(**options) ⇒ Augmenter

Build an augmenter and run augmentation immediately.

Parameters:

  • options (Hash)

    arguments forwarded to new

Returns:



28
29
30
# File 'lib/ast/merge/comment/augmenter.rb', line 28

def call(**options)
  new(**options)
end

Instance Method Details

#attachment_for(owner) ⇒ Attachment?

Return the inferred attachment for a specific owner.

Parameters:

  • owner (Object)

    structural owner

Returns:



58
59
60
# File 'lib/ast/merge/comment/augmenter.rb', line 58

def attachment_for(owner)
  attachments_by_owner[owner]
end