Class: Dotenv::Merge::SmartMerger
- Inherits:
-
Object
- Object
- Dotenv::Merge::SmartMerger
- Defined in:
- lib/dotenv/merge/smart_merger.rb
Overview
Smart merger for dotenv files. Intelligently combines template and destination dotenv files by matching environment variable names and preserving customizations.
Instance Attribute Summary collapse
-
#dest_analysis ⇒ FileAnalysis
readonly
Analysis of destination file.
-
#template_analysis ⇒ FileAnalysis
readonly
Analysis of template file.
Instance Method Summary collapse
-
#initialize(template_content, dest_content, preference: :destination, add_template_only_nodes: false, freeze_token: FileAnalysis::DEFAULT_FREEZE_TOKEN, signature_generator: nil) ⇒ SmartMerger
constructor
Initialize a new SmartMerger.
-
#merge ⇒ String
Perform the merge operation.
-
#merge_result ⇒ MergeResult
Perform the merge operation and return the full result object.
Constructor Details
#initialize(template_content, dest_content, preference: :destination, add_template_only_nodes: false, freeze_token: FileAnalysis::DEFAULT_FREEZE_TOKEN, signature_generator: nil) ⇒ SmartMerger
Initialize a new SmartMerger
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dotenv/merge/smart_merger.rb', line 40 def initialize( template_content, dest_content, preference: :destination, add_template_only_nodes: false, freeze_token: FileAnalysis::DEFAULT_FREEZE_TOKEN, signature_generator: nil ) @preference = preference @add_template_only_nodes = add_template_only_nodes # Parse template @template_analysis = FileAnalysis.new( template_content, freeze_token: freeze_token, signature_generator: signature_generator, ) # Parse destination @dest_analysis = FileAnalysis.new( dest_content, freeze_token: freeze_token, signature_generator: signature_generator, ) @result = MergeResult.new(@template_analysis, @dest_analysis) end |
Instance Attribute Details
#dest_analysis ⇒ FileAnalysis (readonly)
Returns Analysis of destination file.
27 28 29 |
# File 'lib/dotenv/merge/smart_merger.rb', line 27 def dest_analysis @dest_analysis end |
#template_analysis ⇒ FileAnalysis (readonly)
Returns Analysis of template file.
24 25 26 |
# File 'lib/dotenv/merge/smart_merger.rb', line 24 def template_analysis @template_analysis end |
Instance Method Details
#merge ⇒ String
Perform the merge operation
71 72 73 |
# File 'lib/dotenv/merge/smart_merger.rb', line 71 def merge merge_result.to_s end |
#merge_result ⇒ MergeResult
Perform the merge operation and return the full result object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dotenv/merge/smart_merger.rb', line 78 def merge_result return @merge_result if @merge_result @merge_result = DebugLogger.time("SmartMerger#merge") do alignment = align_statements DebugLogger.debug("Alignment complete", { total_entries: alignment.size, matches: alignment.count { |e| e[:type] == :match }, template_only: alignment.count { |e| e[:type] == :template_only }, dest_only: alignment.count { |e| e[:type] == :dest_only }, }) process_alignment(alignment) @result end end |