Class: Toml::Merge::MergeResult
- Inherits:
-
Ast::Merge::MergeResultBase
- Object
- Ast::Merge::MergeResultBase
- Toml::Merge::MergeResult
- Defined in:
- lib/toml/merge/merge_result.rb
Overview
Tracks the result of a merge operation, including the merged content,
decisions made, and statistics.
Inherits decision constants and base functionality from Ast::Merge::MergeResultBase.
Constant Summary collapse
- DECISION_KEPT_TEMPLATE =
Inherit decision constants from base class
Ast::Merge::MergeResultBase::DECISION_KEPT_TEMPLATE
- DECISION_KEPT_DEST =
Ast::Merge::MergeResultBase::DECISION_KEPT_DEST
- DECISION_MERGED =
Ast::Merge::MergeResultBase::DECISION_MERGED
- DECISION_ADDED =
Ast::Merge::MergeResultBase::DECISION_ADDED
Instance Attribute Summary collapse
-
#statistics ⇒ Hash
readonly
Statistics about the merge.
Instance Method Summary collapse
-
#add_blank_line(decision: DECISION_MERGED, source: :merged) ⇒ Object
Add a blank line.
-
#add_line(line, decision:, source:, original_line: nil) ⇒ Object
Add a single line to the result.
-
#add_lines(lines, decision:, source:, start_line: nil) ⇒ Object
Add multiple lines to the result.
-
#add_node(node, decision:, source:, analysis:) ⇒ Object
Add content from a node wrapper.
-
#content ⇒ String
Alias for to_toml.
-
#initialize(**options) ⇒ MergeResult
constructor
Initialize a new merge result.
-
#line_count ⇒ Integer
Get line count.
-
#to_s ⇒ String
Alias for to_toml (used by SmartMerger#merge).
-
#to_toml ⇒ String
Get the merged content as a TOML string.
Constructor Details
#initialize(**options) ⇒ MergeResult
Initialize a new merge result
26 27 28 29 30 31 32 33 34 |
# File 'lib/toml/merge/merge_result.rb', line 26 def initialize(**) super(**) @statistics = { template_lines: 0, dest_lines: 0, merged_lines: 0, total_decisions: 0, } end |
Instance Attribute Details
#statistics ⇒ Hash (readonly)
Returns Statistics about the merge.
22 23 24 |
# File 'lib/toml/merge/merge_result.rb', line 22 def statistics @statistics end |
Instance Method Details
#add_blank_line(decision: DECISION_MERGED, source: :merged) ⇒ Object
Add a blank line
71 72 73 |
# File 'lib/toml/merge/merge_result.rb', line 71 def add_blank_line(decision: DECISION_MERGED, source: :merged) add_line("", decision: decision, source: source) end |
#add_line(line, decision:, source:, original_line: nil) ⇒ Object
Add a single line to the result
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/toml/merge/merge_result.rb', line 42 def add_line(line, decision:, source:, original_line: nil) @lines << { content: line, decision: decision, source: source, original_line: original_line, } track_statistics(decision, source) track_decision(decision, source, line: original_line) end |
#add_lines(lines, decision:, source:, start_line: nil) ⇒ Object
Add multiple lines to the result
60 61 62 63 64 65 |
# File 'lib/toml/merge/merge_result.rb', line 60 def add_lines(lines, decision:, source:, start_line: nil) lines.each_with_index do |line, idx| original_line = start_line ? start_line + idx : nil add_line(line, decision: decision, source: source, original_line: original_line) end end |
#add_node(node, decision:, source:, analysis:) ⇒ Object
Add content from a node wrapper
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/toml/merge/merge_result.rb', line 81 def add_node(node, decision:, source:, analysis:) return unless node.start_line # Use effective_end_line for tables to include associated pairs on Citrus backend # (Citrus has flat structure where pairs are siblings, not children of tables) end_line = node.respond_to?(:effective_end_line) ? node.effective_end_line : node.end_line return unless end_line (node.start_line..end_line).each do |line_num| line = analysis.line_at(line_num) next unless line add_line(line.chomp, decision: decision, source: source, original_line: line_num) end end |
#content ⇒ String
Alias for to_toml
109 110 111 |
# File 'lib/toml/merge/merge_result.rb', line 109 def content to_toml end |
#line_count ⇒ Integer
Get line count
121 122 123 |
# File 'lib/toml/merge/merge_result.rb', line 121 def line_count @lines.size end |
#to_s ⇒ String
Alias for to_toml (used by SmartMerger#merge)
115 116 117 |
# File 'lib/toml/merge/merge_result.rb', line 115 def to_s to_toml end |
#to_toml ⇒ String
Get the merged content as a TOML string
100 101 102 103 104 105 |
# File 'lib/toml/merge/merge_result.rb', line 100 def to_toml content = @lines.map { |l| l[:content] }.join("\n") # Ensure trailing newline content += "\n" unless content.end_with?("\n") || content.empty? content end |