Class: Ast::Merge::Layout::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/layout/attachment.rb

Overview

Passive per-owner container for adjacent blank-line gaps.

An attachment can reference a leading gap, a trailing gap, or both. The same shared gap object may appear in attachments for adjacent owners.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner: nil, leading_gap: nil, trailing_gap: nil, metadata: {}, **options) ⇒ Attachment

Returns a new instance of Attachment.



13
14
15
16
17
18
# File 'lib/ast/merge/layout/attachment.rb', line 13

def initialize(owner: nil, leading_gap: nil, trailing_gap: nil, metadata: {}, **options)
  @owner = owner
  @leading_gap = leading_gap
  @trailing_gap = trailing_gap
  @metadata = .merge(options).freeze
end

Instance Attribute Details

#leading_gapObject (readonly)

Returns the value of attribute leading_gap.



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

def leading_gap
  @leading_gap
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  @metadata
end

#ownerObject (readonly)

Returns the value of attribute owner.



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

def owner
  @owner
end

#trailing_gapObject (readonly)

Returns the value of attribute trailing_gap.



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

def trailing_gap
  @trailing_gap
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ast/merge/layout/attachment.rb', line 27

def empty?
  gaps.empty?
end

#gapsArray<Gap>

Return all distinct gaps referenced by this attachment.

Returns:



23
24
25
# File 'lib/ast/merge/layout/attachment.rb', line 23

def gaps
  [leading_gap, trailing_gap].compact.uniq
end

#inspectString

Return a concise debug representation of the attachment.

Returns:

  • (String)


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

def inspect
  "#<#{self.class.name} owner=#{owner&.class&.name} gaps=#{gaps.size}>"
end

#leading_controls_output?(**options) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ast/merge/layout/attachment.rb', line 31

def leading_controls_output?(**options)
  leading_gap&.controls_output_for?(owner, **options) || false
end

#trailing_controls_output?(**options) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ast/merge/layout/attachment.rb', line 35

def trailing_controls_output?(**options)
  trailing_gap&.controls_output_for?(owner, **options) || false
end