Class: Dotenv::Merge::MergeResult
- Inherits:
-
Ast::Merge::MergeResultBase
- Object
- Ast::Merge::MergeResultBase
- Dotenv::Merge::MergeResult
- Defined in:
- lib/dotenv/merge/merge_result.rb
Overview
Result container for dotenv file merge operations.
Inherits from Ast::Merge::MergeResultBase for shared functionality.
Tracks merged content, decisions made during merge, and provides
methods to reconstruct the final merged dotenv file.
Constant Summary collapse
- DECISION_FREEZE_BLOCK =
Decision indicating content was preserved from a freeze block
:freeze_block- DECISION_TEMPLATE =
Decision indicating content came from the template
:template- DECISION_DESTINATION =
Decision indicating content came from the destination (customization preserved)
:destination- DECISION_ADDED =
Decision indicating content was added from template (new in template)
:added
Instance Method Summary collapse
-
#add_freeze_block(freeze_node) ⇒ void
Add content from a freeze block.
-
#add_from_destination(index, decision: DECISION_DESTINATION) ⇒ void
Add content from the destination at the given statement index.
-
#add_from_template(index, decision: DECISION_TEMPLATE) ⇒ void
Add content from the template at the given statement index.
-
#add_raw(lines, decision:) ⇒ void
Add raw content lines.
-
#empty? ⇒ Boolean
Check if any content has been added.
-
#initialize(template_analysis, dest_analysis, **options) ⇒ MergeResult
constructor
Initialize a new merge result.
-
#summary ⇒ Hash
Get summary of merge decisions.
-
#to_s ⇒ String
Convert the merged result to a string.
Constructor Details
#initialize(template_analysis, dest_analysis, **options) ⇒ MergeResult
Initialize a new merge result
39 40 41 |
# File 'lib/dotenv/merge/merge_result.rb', line 39 def initialize(template_analysis, dest_analysis, **) super(template_analysis: template_analysis, dest_analysis: dest_analysis, **) end |
Instance Method Details
#add_freeze_block(freeze_node) ⇒ void
This method returns an undefined value.
Add content from a freeze block
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dotenv/merge/merge_result.rb', line 72 def add_freeze_block(freeze_node) lines = freeze_node.lines.map(&:raw) @lines.concat(lines) @decisions << { decision: DECISION_FREEZE_BLOCK, source: :destination, start_line: freeze_node.start_line, end_line: freeze_node.end_line, lines: lines.length, } end |
#add_from_destination(index, decision: DECISION_DESTINATION) ⇒ void
This method returns an undefined value.
Add content from the destination at the given statement index
60 61 62 63 64 65 66 67 |
# File 'lib/dotenv/merge/merge_result.rb', line 60 def add_from_destination(index, decision: DECISION_DESTINATION) statement = @dest_analysis.statements[index] return unless statement lines = extract_lines(statement) @lines.concat(lines) @decisions << {decision: decision, source: :destination, index: index, lines: lines.length} end |
#add_from_template(index, decision: DECISION_TEMPLATE) ⇒ void
This method returns an undefined value.
Add content from the template at the given statement index
47 48 49 50 51 52 53 54 |
# File 'lib/dotenv/merge/merge_result.rb', line 47 def add_from_template(index, decision: DECISION_TEMPLATE) statement = @template_analysis.statements[index] return unless statement lines = extract_lines(statement) @lines.concat(lines) @decisions << {decision: decision, source: :template, index: index, lines: lines.length} end |
#add_raw(lines, decision:) ⇒ void
This method returns an undefined value.
Add raw content lines
88 89 90 91 |
# File 'lib/dotenv/merge/merge_result.rb', line 88 def add_raw(lines, decision:) @lines.concat(lines) @decisions << {decision: decision, source: :raw, lines: lines.length} end |
#empty? ⇒ Boolean
Check if any content has been added
106 107 108 |
# File 'lib/dotenv/merge/merge_result.rb', line 106 def empty? @lines.empty? end |
#summary ⇒ Hash
Get summary of merge decisions
112 113 114 115 116 117 118 119 |
# File 'lib/dotenv/merge/merge_result.rb', line 112 def summary counts = @decisions.group_by { |d| d[:decision] }.transform_values(&:count) { total_decisions: @decisions.length, total_lines: @lines.length, by_decision: counts, } end |
#to_s ⇒ String
Convert the merged result to a string
95 96 97 98 99 100 101 102 |
# File 'lib/dotenv/merge/merge_result.rb', line 95 def to_s return "" if @lines.empty? # Join with newlines and ensure file ends with newline result = @lines.join("\n") result += "\n" unless result.end_with?("\n") result end |