Module: Igniter::Extensions::Contracts::Incremental::Formatter

Defined in:
lib/igniter/extensions/contracts/incremental/formatter.rb

Constant Summary collapse

LINE =
"" * 42
VALUE_MAX =
60

Class Method Summary collapse

Class Method Details

.fmt(value) ⇒ Object



50
51
52
53
54
55
# File 'lib/igniter/extensions/contracts/incremental/formatter.rb', line 50

def fmt(value)
  rendered = value.inspect
  return rendered if rendered.length <= VALUE_MAX

  "#{rendered[0, VALUE_MAX - 3]}..."
end

.format(result) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/igniter/extensions/contracts/incremental/formatter.rb', line 13

def format(result)
  lines = []
  lines << "Contracts Incremental Report"
  lines << LINE
  lines << "Recomputed:  #{result.recomputed_count} node(s)"
  lines << "Skipped:     #{result.skipped_nodes.length} node(s)"
  lines << "Backdated:   #{result.backdated_nodes.length} node(s)"
  lines << ""

  if result.changed_outputs.any?
    lines << "CHANGED OUTPUTS (#{result.changed_outputs.length}):"
    result.changed_outputs.each do |name, diff|
      lines << "  :#{name}  #{fmt(diff[:from])} -> #{fmt(diff[:to])}"
    end
  else
    lines << "No output values changed."
  end

  lines << ""
  if result.skipped_nodes.any?
    lines << "SKIPPED:   #{result.skipped_nodes.map do |name|
      ":#{name}"
    end.join("  ")}"
  end
  if result.backdated_nodes.any?
    lines << "BACKDATED: #{result.backdated_nodes.map do |name|
      ":#{name}"
    end.join("  ")}"
  end
  if result.changed_nodes.any?
    lines << "CHANGED:   #{result.changed_nodes.map do |name|
      ":#{name}"
    end.join("  ")}"
  end
  lines.compact.join("\n")
end