Class: RailsTwirp::Command::RoutesCommand

Inherits:
Rails::Command::Base
  • Object
show all
Defined in:
lib/commands/twirp/routes_command.rb

Instance Method Summary collapse

Instance Method Details

#performObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/commands/twirp/routes_command.rb', line 9

def perform
  require_application_and_environment!
  lines = [["Method", "Controller#Action"]]

  Rails.application.twirp.routes.services.each do |svc, route_set|
    route_set.rpcs.each do |name, mapping|
      lines << ["/#{svc.service_full_name}/#{name}", mapping.to_s]
    end
  end

  first_width = lines.map { |line| line[0].length }.max
  second_width = lines.map { |line| line[1].length }.max

  lines.each do |(first, second)|
    say "#{first.rjust(first_width)} #{second.ljust(second_width)}\n"
  end
end