Class: Rubee::CLI::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/rubee/cli/routes.rb

Class Method Summary collapse

Class Method Details

.call(command, argv) ⇒ Object



5
6
7
# File 'lib/rubee/cli/routes.rb', line 5

def call(command, argv)
  send(command, argv)
end

.format_routes(routes) ⇒ Object



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/rubee/cli/routes.rb', line 14

def format_routes(routes)
  if routes.nil? || routes.empty?
    color_puts("No routes found", color: :yellow)
    return
  end

  # Group routes by controller
  grouped = routes.group_by { |r| r[:controller] }

  # Calculate the total width
  width = 100

  puts ""
  color_puts('' * width, color: :cyan)
  color_puts("  APPLICATION ROUTES", color: :cyan, style: :bold)
  color_puts('' * width, color: :cyan)
  puts ""

  grouped.each do |controller, controller_routes|
    # Controller header with dynamic padding
    header_text = "┌─ #{controller.upcase} "
    padding = '' * (width - header_text.length)
    color_puts(header_text + padding, color: :gray, style: :bold)

    controller_routes.each do |route|
      print_route(route)
    end

    # Bottom border
    color_puts("#{'' * (width - 1)}", color: :gray)
  end

  puts ""
  color_puts("Total routes: #{routes.count}", color: :cyan, style: :bold)
end

.routes(_argv) ⇒ Object



9
10
11
12
# File 'lib/rubee/cli/routes.rb', line 9

def routes(_argv)
  routes = Rubee::Router.instance_variable_get(:@routes)
  format_routes(routes)
end