Class: Ast::Merge::MergeResultBase
- Inherits:
-
Object
- Object
- Ast::Merge::MergeResultBase
- Defined in:
- lib/ast/merge/merge_result_base.rb
Overview
Base class for tracking merge results in AST merge libraries. Provides shared decision constants and base functionality for file-type-specific implementations.
Direct Known Subclasses
Constant Summary collapse
- DECISION_KEPT_TEMPLATE =
Line was kept from template (no conflict or template preferred). Used when template content is included without modification.
:kept_template- DECISION_KEPT_DEST =
Line was kept from destination (no conflict or destination preferred). Used when destination content is included without modification.
:kept_destination- DECISION_MERGED =
Line was merged from both sources. Used when content was combined from template and destination.
:merged- DECISION_ADDED =
Line was added from template (template-only content). Used for content that exists only in template and is added to result.
:added- DECISION_FREEZE_BLOCK =
Line from destination freeze block (always preserved). Used for content within freeze markers that must be kept from destination regardless of template content.
:freeze_block- DECISION_REPLACED =
Line replaced matching content (signature match with preference applied). Used when template and destination have nodes with same signature but different content, and one version replaced the other based on preference.
:replaced- DECISION_APPENDED =
Line was appended from destination (destination-only content). Used for content that exists only in destination and is added to result.
:appended
Instance Attribute Summary collapse
-
#conflicts ⇒ Array<Hash>
readonly
Conflicts detected during merge.
-
#decisions ⇒ Array<Hash>
readonly
Decisions made during merge.
-
#dest_analysis ⇒ Object?
readonly
Analysis of the destination file.
-
#frozen_blocks ⇒ Array
readonly
Frozen blocks preserved during merge.
-
#lines ⇒ Array<String>
readonly
Lines in the result (canonical storage for line-by-line merging).
-
#stats ⇒ Hash
readonly
Statistics about the merge.
-
#template_analysis ⇒ Object?
readonly
Analysis of the template file.
Instance Method Summary collapse
-
#content ⇒ Array<String>
Get content - returns @lines array for most gems.
-
#content=(value) ⇒ Object
Set content from a string (splits on newlines).
-
#content? ⇒ Boolean
Check if content has been built (has any lines).
-
#decision_summary ⇒ Hash<Symbol, Integer>
Get summary of decisions made.
-
#empty? ⇒ Boolean
Check if the result is empty.
-
#initialize(template_analysis: nil, dest_analysis: nil, conflicts: [], frozen_blocks: [], stats: {}) ⇒ MergeResultBase
constructor
Initialize a new merge result.
-
#inspect ⇒ String
String representation.
-
#line_count ⇒ Integer
Get the number of lines.
-
#to_s ⇒ String
Get content as a string.
Constructor Details
#initialize(template_analysis: nil, dest_analysis: nil, conflicts: [], frozen_blocks: [], stats: {}) ⇒ MergeResultBase
Initialize a new merge result.
This unified constructor accepts all parameters that any *-merge gem might need. Subclasses should call super with the parameters they use.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ast/merge/merge_result_base.rb', line 79 def initialize( template_analysis: nil, dest_analysis: nil, conflicts: [], frozen_blocks: [], stats: {} ) @template_analysis = template_analysis @dest_analysis = dest_analysis @lines = [] @decisions = [] @conflicts = conflicts @frozen_blocks = frozen_blocks @stats = stats end |
Instance Attribute Details
#conflicts ⇒ Array<Hash> (readonly)
Returns Conflicts detected during merge.
61 62 63 |
# File 'lib/ast/merge/merge_result_base.rb', line 61 def conflicts @conflicts end |
#decisions ⇒ Array<Hash> (readonly)
Returns Decisions made during merge.
52 53 54 |
# File 'lib/ast/merge/merge_result_base.rb', line 52 def decisions @decisions end |
#dest_analysis ⇒ Object? (readonly)
Returns Analysis of the destination file.
58 59 60 |
# File 'lib/ast/merge/merge_result_base.rb', line 58 def dest_analysis @dest_analysis end |
#frozen_blocks ⇒ Array (readonly)
Returns Frozen blocks preserved during merge.
64 65 66 |
# File 'lib/ast/merge/merge_result_base.rb', line 64 def frozen_blocks @frozen_blocks end |
#lines ⇒ Array<String> (readonly)
Returns Lines in the result (canonical storage for line-by-line merging).
49 50 51 |
# File 'lib/ast/merge/merge_result_base.rb', line 49 def lines @lines end |
#stats ⇒ Hash (readonly)
Returns Statistics about the merge.
67 68 69 |
# File 'lib/ast/merge/merge_result_base.rb', line 67 def stats @stats end |
#template_analysis ⇒ Object? (readonly)
Returns Analysis of the template file.
55 56 57 |
# File 'lib/ast/merge/merge_result_base.rb', line 55 def template_analysis @template_analysis end |
Instance Method Details
#content ⇒ Array<String>
Get content - returns @lines array for most gems. Subclasses may override for different content models (e.g., string).
99 100 101 |
# File 'lib/ast/merge/merge_result_base.rb', line 99 def content @lines end |
#content=(value) ⇒ Object
Set content from a string (splits on newlines). Used when region substitution replaces the merged content.
107 108 109 |
# File 'lib/ast/merge/merge_result_base.rb', line 107 def content=(value) @lines = value.to_s.split("\n", -1) end |
#content? ⇒ Boolean
Check if content has been built (has any lines).
123 124 125 |
# File 'lib/ast/merge/merge_result_base.rb', line 123 def content? !@lines.empty? end |
#decision_summary ⇒ Hash<Symbol, Integer>
Get summary of decisions made
141 142 143 144 145 |
# File 'lib/ast/merge/merge_result_base.rb', line 141 def decision_summary summary = Hash.new(0) @decisions.each { |d| summary[d[:decision]] += 1 } summary end |
#empty? ⇒ Boolean
Check if the result is empty
129 130 131 |
# File 'lib/ast/merge/merge_result_base.rb', line 129 def empty? @lines.empty? end |
#inspect ⇒ String
String representation
149 150 151 |
# File 'lib/ast/merge/merge_result_base.rb', line 149 def inspect "#<#{self.class.name} lines=#{line_count} decisions=#{@decisions.length}>" end |
#line_count ⇒ Integer
Get the number of lines
135 136 137 |
# File 'lib/ast/merge/merge_result_base.rb', line 135 def line_count @lines.length end |
#to_s ⇒ String
Get content as a string. This is the canonical method for converting the merge result to a string. Subclasses may override to customize string output (e.g., adding trailing newline).
116 117 118 |
# File 'lib/ast/merge/merge_result_base.rb', line 116 def to_s @lines.join("\n") end |