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: {}, **options) ⇒ 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: {}, **options) ⇒ 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ast/merge/merge_result_base.rb', line 80 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 # **options captured for forward compatibility - subclasses may use additional options 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).
102 103 104 |
# File 'lib/ast/merge/merge_result_base.rb', line 102 def content @lines end |
#content=(value) ⇒ Object
Set content from a string (splits on newlines).
Used when region substitution replaces the merged content.
110 111 112 |
# File 'lib/ast/merge/merge_result_base.rb', line 110 def content=(value) @lines = value.to_s.split("\n", -1) end |
#content? ⇒ Boolean
Check if content has been built (has any lines).
126 127 128 |
# File 'lib/ast/merge/merge_result_base.rb', line 126 def content? !@lines.empty? end |
#decision_summary ⇒ Hash<Symbol, Integer>
Get summary of decisions made
144 145 146 147 148 |
# File 'lib/ast/merge/merge_result_base.rb', line 144 def decision_summary summary = Hash.new(0) @decisions.each { |d| summary[d[:decision]] += 1 } summary end |
#empty? ⇒ Boolean
Check if the result is empty
132 133 134 |
# File 'lib/ast/merge/merge_result_base.rb', line 132 def empty? @lines.empty? end |
#inspect ⇒ String
String representation
152 153 154 |
# File 'lib/ast/merge/merge_result_base.rb', line 152 def inspect "#<#{self.class.name} lines=#{line_count} decisions=#{@decisions.length}>" end |
#line_count ⇒ Integer
Get the number of lines
138 139 140 |
# File 'lib/ast/merge/merge_result_base.rb', line 138 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).
119 120 121 |
# File 'lib/ast/merge/merge_result_base.rb', line 119 def to_s @lines.join("\n") end |