Pippo's blog

it is all about software development

Showing Sinatra Routes

Just missed the rake routes from Rails in a Sinatra app. I didn’t want anything fancy, just a summary of the existing routes to play around. I came up with this:

1
2
3
4
5
6
7
8
9
10
11
require "sinatra/activerecord/rake"
require "./your_app"

task :routes  do
  ["GET", "POST", "PUT", "DELETE"].each do |verb|
    routes = Sinatra::Application.routes[verb] || []
    routes.as_json.flatten.each do |params|
      puts params["route_name"] if params.is_a? Hash
    end
  end
end

And then…

1
rake routes

Comments