-
-
Save jay16/59cc24764a20cd5f52ad to your computer and use it in GitHub Desktop.
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
require './application' | |
namespace :routes do | |
task :show do | |
endpoints = {} | |
if Sinatra::Application.descendants.any? | |
#Classic application structure | |
applications = Sinatra::Application.descendants | |
applications.each do |app| | |
endpoints[app.to_s.downcase.to_sym] = app.routes | |
end | |
elsif Sinatra::Base.descendants.any? | |
#Modular application structure | |
applications = Sinatra::Base.descendants | |
applications.each do |app| | |
endpoints[app.to_s.downcase.to_sym] = app.routes | |
end | |
else | |
abort("Cannot find any defined routes.....") | |
end | |
endpoints.each do |app_name,routes| | |
puts "Application: #{app_name}\n" | |
routes.each do |verb,handlers| | |
puts "\n#{verb}:\n" | |
handlers.each do |handler| | |
puts handler[0].source.to_s | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment