Module: Ast::Merge::TrailingGroups
- Defined in:
- lib/ast/merge/trailing_groups.rb,
lib/ast/merge/trailing_groups/core.rb,
lib/ast/merge/trailing_groups/dest_iterate.rb,
lib/ast/merge/trailing_groups/alignment_sort.rb
Overview
Shared infrastructure for position-aware template-only node interleaving.
When merging a template file into a destination file, nodes that exist only in the template must be inserted at positions that respect their relative ordering among matched (shared) nodes in the template.
Two named patterns are provided:
Pattern A — DestIterate
Used by gems that iterate destination nodes and match against template (prism-merge, psych-merge, json-merge, jsonc-merge, toml-merge, bash-merge).
Includes Core and wraps it with conventional entry points:
- DestIterate#build_dest_iterate_trailing_groups
- DestIterate#emit_prefix_trailing_group
- Delegates to Core#flush_ready_trailing_groups and Core#emit_remaining_trailing_groups
Pattern B — AlignmentSort
Used by gems that build an alignment array and sort template-only entries to their correct positions (dotenv-merge, rbs-merge, markdown-merge, markly-merge, commonmarker-merge).
Provides AlignmentSort#sort_alignment_with_template_position and an overridable AlignmentSort#template_only_sort_key hook.
Defined Under Namespace
Modules: AlignmentSort, Core, DestIterate