Class: Psych::Merge::SmartMerger
- Inherits:
-
Ast::Merge::SmartMergerBase
- Object
- Ast::Merge::SmartMergerBase
- Psych::Merge::SmartMerger
- Defined in:
- lib/psych/merge/smart_merger.rb
Overview
Main entry point for intelligent YAML file merging.
SmartMerger orchestrates the merge process using FileAnalysis,
ConflictResolver, and MergeResult to merge two YAML files intelligently.
Instance Attribute Summary collapse
-
#recursive ⇒ Boolean, Integer
readonly
Whether to merge nested structures recursively.
-
#remove_template_missing_nodes ⇒ Boolean
readonly
Whether to remove destination nodes not in template.
Instance Method Summary collapse
-
#errors ⇒ Array
Get any parse errors from template or destination.
-
#initialize(template_content, dest_content, signature_generator: nil, preference: :destination, add_template_only_nodes: false, remove_template_missing_nodes: false, recursive: true, freeze_token: FileAnalysis::DEFAULT_FREEZE_TOKEN, match_refiner: nil, regions: nil, region_placeholder: nil, node_typing: nil, **options) ⇒ SmartMerger
constructor
Creates a new SmartMerger for intelligent YAML file merging.
-
#merge ⇒ String
Perform the merge and return the result as a YAML string.
-
#merge_with_debug ⇒ Hash
Perform the merge and return detailed results including debug info.
-
#valid? ⇒ Boolean
Check if both files were parsed successfully.
Constructor Details
#initialize(template_content, dest_content, signature_generator: nil, preference: :destination, add_template_only_nodes: false, remove_template_missing_nodes: false, recursive: true, freeze_token: FileAnalysis::DEFAULT_FREEZE_TOKEN, match_refiner: nil, regions: nil, region_placeholder: nil, node_typing: nil, **options) ⇒ SmartMerger
Creates a new SmartMerger for intelligent YAML file merging.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/psych/merge/smart_merger.rb', line 73 def initialize( template_content, dest_content, signature_generator: nil, preference: :destination, add_template_only_nodes: false, remove_template_missing_nodes: false, recursive: true, freeze_token: FileAnalysis::DEFAULT_FREEZE_TOKEN, match_refiner: nil, regions: nil, region_placeholder: nil, node_typing: nil, ** ) @remove_template_missing_nodes = remove_template_missing_nodes @recursive = recursive 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, ** ) end |
Instance Attribute Details
#recursive ⇒ Boolean, Integer (readonly)
Returns Whether to merge nested structures recursively.
109 110 111 |
# File 'lib/psych/merge/smart_merger.rb', line 109 def recursive @recursive end |
#remove_template_missing_nodes ⇒ Boolean (readonly)
Returns Whether to remove destination nodes not in template.
106 107 108 |
# File 'lib/psych/merge/smart_merger.rb', line 106 def remove_template_missing_nodes @remove_template_missing_nodes end |
Instance Method Details
#errors ⇒ Array
Get any parse errors from template or destination.
151 152 153 154 155 156 |
# File 'lib/psych/merge/smart_merger.rb', line 151 def errors errors = [] errors.concat(@template_analysis.errors.map { |e| {source: :template, error: e} }) errors.concat(@dest_analysis.errors.map { |e| {source: :destination, error: e} }) errors end |
#merge ⇒ String
Perform the merge and return the result as a YAML string.
114 115 116 |
# File 'lib/psych/merge/smart_merger.rb', line 114 def merge merge_result.to_yaml end |
#merge_with_debug ⇒ Hash
Perform the merge and return detailed results including debug info.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/psych/merge/smart_merger.rb', line 121 def merge_with_debug content = merge { content: content, statistics: @result.statistics, decisions: @result.decision_summary, template_analysis: { valid: @template_analysis.valid?, statements: @template_analysis.statements.size, freeze_blocks: @template_analysis.freeze_blocks.size, }, dest_analysis: { valid: @dest_analysis.valid?, statements: @dest_analysis.statements.size, freeze_blocks: @dest_analysis.freeze_blocks.size, }, } end |
#valid? ⇒ Boolean
Check if both files were parsed successfully.
144 145 146 |
# File 'lib/psych/merge/smart_merger.rb', line 144 def valid? @template_analysis.valid? && @dest_analysis.valid? end |