Class: Json::Merge::SmartMerger

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

Overview

High-level merger for JSON/JSONC content.
Orchestrates parsing, analysis, and conflict resolution.

Examples:

Basic usage

merger = SmartMerger.new(template_content, dest_content)
result = merger.merge
File.write("merged.json", 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: ObjectMatchRefiner.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, signature_generator: nil, preference: :destination, add_template_only_nodes: false, freeze_token: nil, match_refiner: nil, regions: nil, region_placeholder: nil, node_typing: nil, **options) ⇒ SmartMerger

Creates a new SmartMerger

Parameters:

  • template_content (String)

    Template JSON content

  • dest_content (String)

    Destination JSON content

  • signature_generator (Proc, nil) (defaults to: nil)

    Custom signature generator

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

    :destination, :template, or per-type Hash

  • add_template_only_nodes (Boolean) (defaults to: false)

    Whether to add nodes only found in template

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

    Token for freeze block markers

  • 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

  • node_typing (Hash{Symbol,String => #call}, nil) (defaults to: nil)

    Node typing configuration
    for per-node-type merge preferences

  • options (Hash)

    Additional options for forward compatibility



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/json/merge/smart_merger.rb', line 40

def initialize(
  template_content,
  dest_content,
  signature_generator: nil,
  preference: :destination,
  add_template_only_nodes: false,
  freeze_token: nil,
  match_refiner: nil,
  regions: nil,
  region_placeholder: nil,
  node_typing: nil,
  **options
)
  super(
    template_content,
    dest_content,
    signature_generator: signature_generator,
    preference: preference,
    add_template_only_nodes: add_template_only_nodes,
    freeze_token: freeze_token,
    match_refiner: match_refiner,
    regions: regions,
    region_placeholder: region_placeholder,
    node_typing: node_typing,
    **options
  )
end

Instance Method Details

#optionsHash

Backward-compatible options hash

Returns:

  • (Hash)

    The merge options



71
72
73
74
75
76
77
# File 'lib/json/merge/smart_merger.rb', line 71

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