Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created November 25, 2015 14:23
Show Gist options
  • Save rummelonp/f48b880588f992b3ba22 to your computer and use it in GitHub Desktop.
Save rummelonp/f48b880588f992b3ba22 to your computer and use it in GitHub Desktop.
Grape の routes 出すやつ
namespace :api do
desc 'API Routes'
task routes: :environment do
routes = API.routes
headers = ['Version', 'Method', 'Path']
widths = [
routes.map { |r| r.route_version.size }.max || 0,
routes.map { |r| r.route_method.size }.max || 0,
routes.map { |r| r.route_path.size }.max || 0
]
version_width, method_width, path_width = widths.zip(headers.map(&:size)).map(&:max)
puts [
'Version'.rjust(version_width),
'Method'.ljust(method_width),
'Path'.ljust(path_width),
].join(' ')
routes.each do |r|
puts [
r.route_version.rjust(version_width),
r.route_method.ljust(method_width),
r.route_path.ljust(path_width),
].join(' ')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment