Last active
August 29, 2015 13:57
-
-
Save hnq90/9898206 to your computer and use it in GitHub Desktop.
List all routes of grape app and export to text file
This file contains 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
desc 'Generate API Desc' | |
task :api_desc => :environment do | |
=begin | |
___ ___ ___ ___ ___ ___ ________ ________ | |
|\ \|\ \|\ \|\ \ |\ \ / /|\ ___ \|\ __ \ | |
\ \ \\\ \ \ \\\ \ \ \ \/ / | \ \\ \ \ \ \|\ \ | |
\ \ __ \ \ \\\ \ \ \ / / \ \ \\ \ \ \ \\\ \ | |
\ \ \ \ \ \ \\\ \ \/ / / \ \ \\ \ \ \ \\\ \ | |
\ \__\ \__\ \_______\__/ / / \ \__\\ \__\ \_____ \ | |
\|__|\|__|\|_______|\___/ / \|__| \|__|\|___| \__\ | |
\|___|/ \|__| | |
=end | |
routes = Api::Root::routes | |
info = String.new | |
f = File.new("api_routes.txt", 'wb') | |
info << "#####################################################\n" | |
info << "## Script Generate List of API on Grape-based app ##\n" | |
info << "## Author: HuyNQ (huy@huynq.net) ##\n" | |
info << "## Date: 2014/04/01 ##\n" | |
info << "#####################################################\n\n\n" | |
routes.count.times do |i| | |
info << "#{i+1}. " << routes[i].route_description.to_s << "\n" | |
info << "\t Params: " << "\n" | |
routes[i].route_params.each do |k,_| | |
info << "\t\t- " << k | |
if routes[i].route_params[k].length > 0 | |
info << "\t Required: " << routes[i].route_params[k][:required].to_s | |
info << "\t Type: #{routes[i].route_params[k][:type].to_s}" | |
info << "\t Desc: #{routes[i].route_params[k][:desc].to_s if routes[i].route_params[k].length > 0} \n" | |
end | |
end | |
info << "\t Method: " << routes[i].route_method.to_s << "\n" | |
info << "\t Path: " << routes[i].route_path.to_s.gsub("(.:format)", "") << "\n\n" | |
end | |
f << info | |
f.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment