Class: Psych::Merge::ConflictResolver

Inherits:
Ast::Merge::ConflictResolverBase
  • Object
show all
Includes:
Ast::Merge::CommentLayoutEmissionSupport, Ast::Merge::StructuredEmitterProvenanceSupport, Ast::Merge::TrailingGroups::DestIterate
Defined in:
lib/psych/merge/conflict_resolver.rb

Overview

Resolves conflicts between template and destination YAML content using structural signatures and configurable preferences.

Inherits from Ast::Merge::ConflictResolverBase using the :batch strategy, which resolves all conflicts at once using signature maps.

Examples:

Basic usage

resolver = ConflictResolver.new(template_analysis, dest_analysis)
resolver.resolve(result)

With recursive merge for nested structures

resolver = ConflictResolver.new(
  template_analysis,
  dest_analysis,
  recursive: true,
  add_template_only_nodes: true
)

See Also:

  • Ast::Merge::ConflictResolverBase

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_analysis, dest_analysis, preference: :destination, add_template_only_nodes: false, add_template_only_sequence_items: nil, remove_template_missing_nodes: false, resolution_mode: :eager, corruption_handling: :heal, recursive: true, match_refiner: nil, node_typing: nil, comment_merge_policy: :preserve_destination, **options) ⇒ ConflictResolver

Creates a new ConflictResolver

Parameters:

  • template_analysis (FileAnalysis)

    Analyzed template file

  • dest_analysis (FileAnalysis)

    Analyzed destination file

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

    Which version to prefer when nodes have matching signatures:

    • :destination (default) - Keep destination version (customizations)
    • :template - Use template version (updates)
  • add_template_only_nodes (Boolean) (defaults to: false)

    Whether to add nodes only in template

  • remove_template_missing_nodes (Boolean) (defaults to: false)

    Whether to remove destination nodes not in template

  • recursive (Boolean, Integer) (defaults to: true)

    Whether to merge nested structures recursively

    • true: unlimited depth (default)
    • false: disabled
    • Integer > 0: max depth
  • match_refiner (#call, nil) (defaults to: nil)

    Optional match refiner for fuzzy matching

  • options (Hash)

    Additional options for forward compatibility

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

    Node typing configuration for per-node-type preferences



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/psych/merge/conflict_resolver.rb', line 49

def initialize(template_analysis, dest_analysis, preference: :destination, add_template_only_nodes: false,
               add_template_only_sequence_items: nil, remove_template_missing_nodes: false, resolution_mode: :eager, corruption_handling: :heal, recursive: true, match_refiner: nil, node_typing: nil, comment_merge_policy: :preserve_destination, **options)
  super(
    strategy: :batch,
    preference: preference,
    template_analysis: template_analysis,
    dest_analysis: dest_analysis,
    add_template_only_nodes: add_template_only_nodes,
    remove_template_missing_nodes: remove_template_missing_nodes,
    recursive: recursive,
    match_refiner: match_refiner,
    **options
  )
  @resolution_mode = resolution_mode
  @corruption_handling = ::Ast::Merge::Healer.normalize_mode(corruption_handling)
  @add_template_only_sequence_items = add_template_only_sequence_items.nil? ? add_template_only_nodes : add_template_only_sequence_items
  @node_typing = node_typing
  @comment_merge_policy = normalize_comment_merge_policy(comment_merge_policy)
  @emitter = Emitter.new
  @last_document_node_recursively_merged = false
end

Instance Attribute Details

#corruption_handlingObject (readonly)

Returns the value of attribute corruption_handling.



29
30
31
# File 'lib/psych/merge/conflict_resolver.rb', line 29

def corruption_handling
  @corruption_handling
end