Module: Ast::Merge::Layout
- Defined in:
- lib/ast/merge/layout.rb,
lib/ast/merge/layout/gap.rb,
lib/ast/merge/layout/policy.rb,
lib/ast/merge/layout/augmenter.rb,
lib/ast/merge/layout/attachment.rb
Overview
Shared merge-facing layout abstractions.
Ast::Merge::Layout models interstitial blank-line runs in a way that lets
adjacent nodes both be aware of the same gap while ensuring only one side
controls output at a time.
Defined Under Namespace
Classes: Attachment, Augmenter, Gap, Policy
Class Method Summary collapse
- .owner_controls_gap?(owner, gap) ⇒ Boolean
- .prune_emitted_leading_gap_for_removed_owner(result:, attachment:) ⇒ Object
- .removed_owner_controlled_gaps(attachment) ⇒ Object
Class Method Details
.owner_controls_gap?(owner, gap) ⇒ Boolean
18 19 20 |
# File 'lib/ast/merge/layout.rb', line 18 def owner_controls_gap?(owner, gap) !!(owner && gap&.controls_output_for?(owner)) end |
.prune_emitted_leading_gap_for_removed_owner(result:, attachment:) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/ast/merge/layout.rb', line 31 def prune_emitted_leading_gap_for_removed_owner(result:, attachment:) gap = removed_owner_controlled_gaps()[:leading] return 0 unless gap return 0 unless result.respond_to?(:remove_trailing_blank_lines) result.remove_trailing_blank_lines(max: gap.blank_line_count) end |
.removed_owner_controlled_gaps(attachment) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/ast/merge/layout.rb', line 22 def removed_owner_controlled_gaps() return {} unless .respond_to?(:owner) { leading: (.leading_gap if owner_controls_gap?(.owner, .leading_gap)), trailing: (.trailing_gap if owner_controls_gap?(.owner, .trailing_gap)) }.compact end |