Class: Yaml::Merge::MergeResult

Inherits:
Ast::Merge::MergeResultBase
  • Object
show all
Defined in:
lib/yaml/merge/merge_result.rb

Constant Summary collapse

DECISION_KEPT_TEMPLATE =
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
DECISION_FREEZE_BLOCK =
Ast::Merge::MergeResultBase::DECISION_FREEZE_BLOCK

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ MergeResult

Returns a new instance of MergeResult.



14
15
16
17
18
19
20
21
22
23
# File 'lib/yaml/merge/merge_result.rb', line 14

def initialize(**options)
  super(**options)
  @statistics = {
    template_lines: 0,
    dest_lines: 0,
    merged_lines: 0,
    freeze_preserved_lines: 0,
    total_decisions: 0
  }
end

Instance Attribute Details

#statisticsObject (readonly)

Returns the value of attribute statistics.



12
13
14
# File 'lib/yaml/merge/merge_result.rb', line 12

def statistics
  @statistics
end

Instance Method Details

#add_line(line, decision:, source:, original_line: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/yaml/merge/merge_result.rb', line 25

def add_line(line, decision:, source:, original_line: nil)
  @lines << {
    content: line,
    decision: decision,
    source: source,
    original_line: original_line
  }
  track_statistics(decision)
  track_decision(decision, source, line: original_line)
end

#line_countObject



45
46
47
# File 'lib/yaml/merge/merge_result.rb', line 45

def line_count
  @lines.size
end

#to_yamlObject Also known as: content, to_s



36
37
38
39
40
# File 'lib/yaml/merge/merge_result.rb', line 36

def to_yaml
  content = @lines.map { |line| line[:content] }.join("\n")
  content += "\n" unless content.empty? || content.end_with?("\n")
  content
end