Class: AuthenticationWarningDisplay

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

Instance Method Summary collapse

Constructor Details

#initialize(pastel) ⇒ AuthenticationWarningDisplay



9
10
11
12
13
14
15
16
# File 'lib/tng/ui/authentication_warning_display.rb', line 9

def initialize(pastel)
  @pastel = pastel
  @terminal_width = begin
    TTY::Screen.width
  rescue StandardError
    80
  end
end

Instance Method Details

#display_if_missingObject



18
19
20
21
22
23
# File 'lib/tng/ui/authentication_warning_display.rb', line 18

def display_if_missing
  return false unless authentication_config_missing?

  display_warning
  handle_user_choice
end

#display_warningObject



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

def display_warning
  warning_content = [
    @pastel.public_send(Tng::UI::Theme.color(:error)).bold("Authentication Configuration Missing"),
    "",
    @pastel.public_send(Tng::UI::Theme.color(:primary), "TNG needs authentication setup to generate proper tests."),
    "",
    @pastel.public_send(Tng::UI::Theme.color(:accent), "Missing: ") + build_missing_items_summary,
    "",
    @pastel.public_send(Tng::UI::Theme.color(:secondary), "Quick fix:"),
    @pastel.public_send(Tng::UI::Theme.color(:muted),
                        "#{Tng::UI::Theme.icon(:bullet)} Edit config/initializers/tng.rb"),
    @pastel.public_send(Tng::UI::Theme.color(:muted),
                        "#{Tng::UI::Theme.icon(:bullet)} Uncomment authentication_methods array"),
    @pastel.public_send(Tng::UI::Theme.color(:muted), "#{Tng::UI::Theme.icon(:bullet)} Add your auth method details"),
    "",
    @pastel.public_send(Tng::UI::Theme.color(:success), "Press Enter to continue anyway"),
    @pastel.public_send(Tng::UI::Theme.color(:error), "Press Esc to cancel and fix configuration")
  ].join("\n")

  box_width = Tng::UI::Theme.calculate_box_width(@terminal_width)
  style = Tng::UI::Theme.box_style(:warning)

  warning_box = TTY::Box.frame(
    title: { top_left: " Auth Warning " },
    style: style[:style],
    padding: style[:padding],
    width: box_width
  ) do
    warning_content
  end

  puts Tng::UI::Theme.center_box(warning_box, box_width, @terminal_width)
  puts
end