Module: Railbow::RoutesFormatter

Defined in:
lib/railbow/routes_formatter.rb

Constant Summary collapse

VERB_COLORS =
{
  "GET" => Formatters::Base::GREEN,
  "POST" => Formatters::Base::YELLOW,
  "PATCH" => Formatters::Base::CYAN,
  "PUT" => Formatters::Base::CYAN,
  "DELETE" => Formatters::Base::RED
}.freeze
RESET =
Formatters::Base::RESET
BOLD =
Formatters::Base::BOLD
DIM =
Formatters::Base::DIM
CYAN =
Formatters::Base::CYAN
HELP_TEXT_COLOR =
"\n\#{BOLD}Railbow Routes Options:\#{RESET}\n\n  \#{CYAN}RBW_VERB=GET\#{RESET}          Show only GET routes\n  \#{CYAN}RBW_VERB=POST,PUT\#{RESET}     Show only POST and PUT routes\n  \#{CYAN}RBW_COMPACT=strip-format\#{RESET}  Strip (.:format) suffixes\n  \#{CYAN}RBW_COMPACT=oneline\#{RESET}   Truncate instead of wrapping\n  \#{CYAN}RBW_COMPACT=dense\#{RESET}     Remove cell padding\n  \#{CYAN}RBW_COMPACT=noheader\#{RESET}  Hide table header row\n  \#{CYAN}RBW_COMPACT=maxw:40\#{RESET}   Cap column widths\n  \#{CYAN}RBW_COMPACT=hide:prefix\#{RESET}  Hide a column by name\n  \#{CYAN}RBW_PLAIN=1\#{RESET}           Disable Railbow formatting (plain Rails output)\n  \#{CYAN}RBW_HELP=1\#{RESET}            Show this help message\n\n\#{DIM}Combine: RBW_COMPACT=strip-format,dense,noheader\#{RESET}\n\#{DIM}Auto-disabled when piped, in CI, or when called by an LLM agent.\#{RESET}\n\#{DIM}Example: RBW_VERB=GET rails routes\#{RESET}\n\n"

Instance Method Summary collapse

Instance Method Details

#header(routes) ⇒ Object



50
51
52
# File 'lib/railbow/routes_formatter.rb', line 50

def header(routes)
  super unless tty?
end

#section(routes) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/railbow/routes_formatter.rb', line 54

def section(routes)
  return super unless tty?

  if Railbow::Params.help?
    unless @help_shown
      @buffer << HELP_TEXT_COLOR
      @help_shown = true
    end
    return
  end

  strip_format = Railbow::Params.compact_strip_format?
  prepared = routes.map { |r| prepare_route(r, strip_format) }
  prepared = filter_by_verb(prepared)

  groups = group_routes(prepared)
  groups.each { |label, group| render_group(label, group) }
end

#section_title(title) ⇒ Object



43
44
45
46
47
48
# File 'lib/railbow/routes_formatter.rb', line 43

def section_title(title)
  return super unless tty?
  return if Railbow::Params.help?

  @buffer << "\n#{BOLD}#{CYAN}#{title}:#{RESET}"
end