Class: SystemStatusDisplay

Inherits:
Object
  • Object
show all
Defined in:
lib/tng/ui/system_status_display.rb

Instance Method Summary collapse

Constructor Details

#initialize(pastel, args) ⇒ SystemStatusDisplay

Returns a new instance of SystemStatusDisplay.



7
8
9
10
# File 'lib/tng/ui/system_status_display.rb', line 7

def initialize(pastel, args)
  @pastel = pastel
  @args = args
end

Instance Method Details

#display(status) ⇒ Object



12
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
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
# File 'lib/tng/ui/system_status_display.rb', line 12

def display(status)
  case status[:status]
  when :ok
    unless @args[:type] && @args[:file]
      puts @pastel.public_send(Tng::UI::Theme.color(:success),
                               "#{Tng::UI::Theme.icon(:success)} System operational")
    end
    true
  when :version_mismatch
    display_status_message(
      title: "Version Mismatch",
      icon: Tng::UI::Theme.icon(:error),
      color: Tng::UI::Theme.color(:error),
      content: [
        "Your gem version: #{status[:gem_version]}",
        "Required version: #{status[:current_version]}",
        "",
        "Quick fix:",
        "• gem update tng",
        "• bundle update tng"
      ]
    )
    false
  when :base_url_mismatch
    display_status_message(
      title: "URL Mismatch",
      icon: Tng::UI::Theme.icon(:error),
      color: Tng::UI::Theme.color(:error),
      content: [
        "Your URL: #{status[:user_base_url]}",
        "Server URL: #{status[:server_base_url]}",
        "",
        "Quick fix:",
        "• Edit config/initializers/tng.rb",
        "• Set: config.base_url = '#{status[:server_base_url]}'"
      ]
    )
    false
  when :service_down
    display_status_message(
      title: "Service Unavailable",
      icon: Tng::UI::Theme.icon(:error),
      color: Tng::UI::Theme.color(:error),
      content: [
        status[:message] || "TNG service is currently down",
        "",
        "Please try again later or contact support"
      ]
    )
    false
  when :error
    display_status_message(
      title: "Connection Error",
      icon: Tng::UI::Theme.icon(:error),
      color: Tng::UI::Theme.color(:error),
      content: [
        status[:message] || "Unable to connect to TNG service",
        "",
        "Please check your internet connection and try again"
      ]
    )
    false
  else
    display_status_message(
      title: "Unknown Error",
      icon: Tng::UI::Theme.icon(:error),
      color: Tng::UI::Theme.color(:error),
      content: [status[:message] || "An unknown error occurred"]
    )
    false
  end
end