Skip to content

Instantly share code, notes, and snippets.

@hnq90
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnq90/9898206 to your computer and use it in GitHub Desktop.
Save hnq90/9898206 to your computer and use it in GitHub Desktop.
List all routes of grape app and export to text file
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