Class: Rbs::Merge::SmartMerger

Inherits:
Ast::Merge::SmartMergerBase
  • Object
show all
Includes:
Ast::Merge::CommentLayoutEmissionSupport
Defined in:
lib/rbs/merge/smart_merger.rb

Overview

Orchestrates the smart merge process for RBS type signature files. Uses FileAnalysis, FileAligner, ConflictResolver, and MergeResult to merge two RBS files intelligently.

SmartMerger provides flexible configuration for different merge scenarios. When matching class or module definitions are found in both files, the merger can perform recursive merging of their members.

Examples:

Basic merge (destination customizations preserved)

merger = SmartMerger.new(template_content, dest_content)
result = merger.merge

Template updates win

merger = SmartMerger.new(
  template_content,
  dest_content,
  preference: :template,
  add_template_only_nodes: true
)
result = merger.merge

Custom signature matching

sig_gen = ->(node) { [:decl, node.name.to_s] }
merger = SmartMerger.new(
  template_content,
  dest_content,
  signature_generator: sig_gen
)

With node_typing for per-node-type preferences

merger = SmartMerger.new(template, dest,
  node_typing: { "ClassDecl" => ->(n) { NodeTyping.with_merge_type(n, :model) } },
  preference: { default: :destination, model: :template })

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_content, dest_content, signature_generator: nil, preference: :destination, add_template_only_nodes: false, remove_template_missing_nodes: false, corruption_handling: :heal, freeze_token: nil, match_refiner: nil, regions: nil, region_placeholder: nil, node_typing: nil, max_recursion_depth: Float::INFINITY, **options) ⇒ SmartMerger

Creates a new SmartMerger for intelligent RBS file merging.

Raises:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rbs/merge/smart_merger.rb', line 87

def initialize(
  template_content,
  dest_content,
  signature_generator: nil,
  preference: :destination,
  add_template_only_nodes: false,
  remove_template_missing_nodes: false,
  corruption_handling: :heal,
  freeze_token: nil,
  match_refiner: nil,
  regions: nil,
  region_placeholder: nil,
  node_typing: nil,
  max_recursion_depth: Float::INFINITY,
  **options
)
  @max_recursion_depth = max_recursion_depth
  @remove_template_missing_nodes = remove_template_missing_nodes
  @corruption_handling = ::Ast::Merge::Healer.normalize_mode(corruption_handling)
  super(
    template_content,
    dest_content,
    signature_generator: signature_generator,
    preference: preference,
    add_template_only_nodes: add_template_only_nodes,
    remove_template_missing_nodes: remove_template_missing_nodes,
    freeze_token: freeze_token,
    match_refiner: match_refiner,
    regions: regions,
    region_placeholder: region_placeholder,
    node_typing: node_typing,
    **options
  )
end

Instance Attribute Details

#corruption_handlingObject (readonly)

Returns the value of attribute corruption_handling.



46
47
48
# File 'lib/rbs/merge/smart_merger.rb', line 46

def corruption_handling
  @corruption_handling
end