Skip to content

Instantly share code, notes, and snippets.

@gary-rafferty
Created January 9, 2012 19:56
Show Gist options
  • Save gary-rafferty/1584624 to your computer and use it in GitHub Desktop.
Save gary-rafferty/1584624 to your computer and use it in GitHub Desktop.
Rake task to show my Sinatra routes (probably not reusable)
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