Class: Equilibrium::SummaryFormatter

Inherits:
Object
  • Object
show all
Includes:
Thor::Shell
Defined in:
lib/equilibrium/summary_formatter.rb

Instance Method Summary collapse

Constructor Details

#initializeSummaryFormatter

Returns a new instance of SummaryFormatter.



9
10
11
12
# File 'lib/equilibrium/summary_formatter.rb', line 9

def initialize
  # Initialize Thor::Shell methods with empty arguments
  self.shell = Thor::Shell::Basic.new
end

Instance Method Details



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/equilibrium/summary_formatter.rb', line 14

def print_analysis_summary(analysis)
  say "Repository URL: #{analysis[:repository_url]}"
  say ""

  # Status overview table
  status_color = (analysis[:status] == "perfect") ? :green : :yellow
  status_symbol = (analysis[:status] == "perfect") ? "✓" : "⚠"

  overview_data = [
    ["Metric", "Count"],
    ["Expected tags", analysis[:expected_count].to_s],
    ["Actual tags", analysis[:actual_count].to_s],
    ["Missing tags", analysis[:missing_tags].size.to_s],
    ["Mismatched tags", analysis[:mismatched_tags].size.to_s],
    ["Unexpected tags", analysis[:unexpected_tags].size.to_s]
  ]

  say "Analysis Overview:"
  print_table(overview_data, borders: true)
  say ""

  say "#{status_symbol} Status: #{analysis[:status].upcase.tr("_", " ")}", status_color
  say ""

  # Show specific issue sections
  has_issues = false

  # Missing tags section
  if analysis[:missing_tags].any?
    has_issues = true
    say "Missing Tags (should be created):"
    missing_table = [["Tag", "Should Point To"]]
    analysis[:missing_tags].each do |tag, details|
      full_digest = details[:expected] || "unknown"
      missing_table << [tag, full_digest]
    end
    print_table(missing_table, borders: true)
    say ""
  end

  # Mismatched tags section
  if analysis[:mismatched_tags].any?
    has_issues = true
    say "Mismatched Tags (pointing to wrong version):"
    mismatched_table = [["Tag", "Expected", "Actual"]]
    analysis[:mismatched_tags].each do |tag, details|
      if details.is_a?(Hash)
        expected = details[:expected] || "unknown"
        actual = details[:actual] || "unknown"
      else
        expected = details || "unknown"
        actual = "unknown"
      end
      mismatched_table << [tag, expected, actual]
    end
    print_table(mismatched_table, borders: true)
    say ""
  end

  # Unexpected tags section
  if analysis[:unexpected_tags].any?
    has_issues = true
    say "Unexpected Tags (should be removed):"
    unexpected_table = [["Tag", "Currently Points To"]]
    analysis[:unexpected_tags].each do |tag, details|
      full_digest = details[:actual] || "unknown"
      unexpected_table << [tag, full_digest]
    end
    print_table(unexpected_table, borders: true)
    say ""
  end

  if has_issues
    say "To see detailed analysis data, use:"
    say "  equilibrium analyze --expected expected.json --actual actual.json --format=json"
  else
    say "✓ Registry is in perfect equilibrium!", :green
  end
end


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/equilibrium/summary_formatter.rb', line 94

def print_tags_summary(output, type)
  say "Repository: #{output["repository_name"]}"
  say "URL: #{output["repository_url"]}"
  say ""

  mutable_tags = output["digests"]
  canonical_versions = output["canonical_versions"]

  say "#{type.capitalize} mutable tags (#{mutable_tags.size}):"
  say ""

  # Create table data: [["Tag", "Version", "Digest"]]
  table_data = [["Tag", "Version", "Digest"]]
  mutable_tags.keys.each do |tag|
    canonical_version = canonical_versions[tag]
    digest = mutable_tags[tag]
    table_data << [tag, canonical_version, digest]
  end

  print_table(table_data, borders: true)
end