WeTransfer / apiculture

Honey-tasting REST API toolkit for Sinatra
MIT License
12 stars 3 forks source link

Feature: Output routes in "rake routes" look and feel #3

Open dennisvdvliet opened 8 years ago

dennisvdvliet commented 8 years ago

Something this:

routes = Alligator::V1.apiculture_stack.select{|d| d.is_a? Apiculture::ActionDefinition}
prefix = Alligator::V1.instance_variable_get(:@apiculture_mounted_at)
format = "%7s %-75s %-50s\n"
routes.each do |route|
  printf format % [route.http_verb.upcase, prefix + route.path, route.description]
end

But a little less hacky

julik commented 8 years ago

Maybe MyApp.action_routes.each { ... }?

julik commented 8 years ago

Why don't we piggyback on the Sinatra way of doing it? Like here: http://stackoverflow.com/questions/13694058/how-to-get-a-list-of-all-routes-used-in-a-sinatra-app

This way we can first get all the routes of the app, and maybe print route definitions from Apiculture as well if they intersect. We can also overload Sinatra::Base#routes and augment the stuff returned from it with Apicluture metadata if it is available for a specific route. And printing the routes will then be handled externally in any way the user sees fit. Yay?