Created
November 25, 2015 14:23
-
-
Save rummelonp/f48b880588f992b3ba22 to your computer and use it in GitHub Desktop.
Grape の routes 出すやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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