Class: Ast::Merge::Layout::Augmenter

Inherits:
Object
  • Object
show all
Includes:
Ast::Merge::LineRangeSupport
Defined in:
lib/ast/merge/layout/augmenter.rb

Overview

Builds shared blank-line gap objects and per-owner attachments from source lines plus structural owner ranges.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines: nil, source: nil, owners: [], start_line_for: nil, end_line_for: nil, metadata: {}, **options) ⇒ Augmenter

Returns a new instance of Augmenter.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ast/merge/layout/augmenter.rb', line 23

def initialize(lines: nil, source: nil, owners: [], start_line_for: nil, end_line_for: nil, metadata: {},
               **options)
  @lines = normalize_lines(lines, source)
  @start_line_for = start_line_for
  @end_line_for = end_line_for
  @owners = normalize_owners(owners)
  @metadata = .merge(options).freeze
  @attachments_by_owner = {}
  @preamble_gap = nil
  @postlude_gap = nil
  @interstitial_gaps = []

  build!
end

Instance Attribute Details

#attachments_by_ownerObject (readonly)

Returns the value of attribute attachments_by_owner.



11
12
13
# File 'lib/ast/merge/layout/augmenter.rb', line 11

def attachments_by_owner
  @attachments_by_owner
end

#interstitial_gapsObject (readonly)

Returns the value of attribute interstitial_gaps.



11
12
13
# File 'lib/ast/merge/layout/augmenter.rb', line 11

def interstitial_gaps
  @interstitial_gaps
end

#linesObject (readonly)

Returns the value of attribute lines.



11
12
13
# File 'lib/ast/merge/layout/augmenter.rb', line 11

def lines
  @lines
end

#metadataObject (readonly)

Returns the value of attribute metadata.



11
12
13
# File 'lib/ast/merge/layout/augmenter.rb', line 11

def 
  @metadata
end

#ownersObject (readonly)

Returns the value of attribute owners.



11
12
13
# File 'lib/ast/merge/layout/augmenter.rb', line 11

def owners
  @owners
end

#postlude_gapObject (readonly)

Returns the value of attribute postlude_gap.



11
12
13
# File 'lib/ast/merge/layout/augmenter.rb', line 11

def postlude_gap
  @postlude_gap
end

#preamble_gapObject (readonly)

Returns the value of attribute preamble_gap.



11
12
13
# File 'lib/ast/merge/layout/augmenter.rb', line 11

def preamble_gap
  @preamble_gap
end

Class Method Details

.call(**options) ⇒ Augmenter

Build an augmenter and run gap inference immediately.

Parameters:

  • options (Hash)

    arguments forwarded to new

Returns:



18
19
20
# File 'lib/ast/merge/layout/augmenter.rb', line 18

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:



42
43
44
# File 'lib/ast/merge/layout/augmenter.rb', line 42

def attachment_for(owner)
  attachments_by_owner[owner]
end

#gapsArray<Gap>

Return all inferred gaps in source order.

Returns:



49
50
51
# File 'lib/ast/merge/layout/augmenter.rb', line 49

def gaps
  [preamble_gap, *interstitial_gaps, postlude_gap].compact
end