Class: Toml::Merge::SmartMerger

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

Overview

High-level merger for TOML content. Orchestrates parsing, analysis, and conflict resolution.

Examples:

Basic usage

merger = SmartMerger.new(template_content, dest_content)
result = merger.merge
File.write("merged.toml", result.output)

With options

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

Enable fuzzy matching

merger = SmartMerger.new(template, dest, match_refiner: TableMatchRefiner.new)

With regions (embedded content)

merger = SmartMerger.new(template, dest,
  regions: [{ detector: SomeDetector.new, merger_class: SomeMerger }])

Instance Method Summary collapse

Constructor Details

#initialize(template_content, dest_content, preference: :destination, add_template_only_nodes: false, match_refiner: nil, regions: nil, region_placeholder: nil) ⇒ SmartMerger

Creates a new SmartMerger

Parameters:

  • template_content (String)

    Template TOML content

  • dest_content (String)

    Destination TOML content

  • preference (Symbol) (defaults to: :destination)

    :destination or :template

  • add_template_only_nodes (Boolean) (defaults to: false)

    Whether to add nodes only found in template

  • match_refiner (#call, nil) (defaults to: nil)

    Match refiner for fuzzy matching

  • regions (Array<Hash>, nil) (defaults to: nil)

    Region configurations for nested merging

  • region_placeholder (String, nil) (defaults to: nil)

    Custom placeholder for regions



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/toml/merge/smart_merger.rb', line 35

def initialize(
  template_content,
  dest_content,
  preference: :destination,
  add_template_only_nodes: false,
  match_refiner: nil,
  regions: nil,
  region_placeholder: nil
)
  super(
    template_content,
    dest_content,
    preference: preference,
    add_template_only_nodes: add_template_only_nodes,
    match_refiner: match_refiner,
    regions: regions,
    region_placeholder: region_placeholder,
  )
end

Instance Method Details

#optionsHash

Backward-compatible options hash

Returns:

  • (Hash)

    The merge options



58
59
60
61
62
63
64
# File 'lib/toml/merge/smart_merger.rb', line 58

def options
  {
    preference: @preference,
    add_template_only_nodes: @add_template_only_nodes,
    match_refiner: @match_refiner,
  }
end