soveran / cuba

Rum based microframework for web development.
http://cuba.is
MIT License
1.44k stars 249 forks source link

List of "routes" declared in the app #65

Closed rhymes closed 8 years ago

rhymes commented 9 years ago

It would be awesome to have a sort of rake routes to have the list of the defined URL that the Cuba app can match on.

If you give me some pointers into the code I can try to code it myself and submit a PR.

Thanks!

soveran commented 9 years ago

Hey @rhymes, I'm afraid it's a very difficult (or impossible!) task. In Rails, the routes are compiled and can be observed later. What you get in that list is something like the following:

users GET    /users(.:format)          users#index
      POST   /users(.:format)          users#create

In that list, you only see the REQUEST_METHOD and the path matcher. In Cuba, you can match against anything, and you can nest the routes in different ways. Because of that, building a list of routes is as difficult as building a list of possible matches for an arbitrary regular expression. As that list is infinite, there's no simple way to create a user friendly representation. I won't close the issue right away so that others can participate and share their point of view.

rhymes commented 9 years ago

@soveran I understand. Thanks for the explanation.

Do you think that keeping a compiled list of the matchers benefits speed in Cuba's case? Maybe we can just print those.

F-3r commented 9 years ago

This is perhaps kind of a "caveman approach", but perhaps is transformable into a good idea?

We ussually have our cuba apps under /apps dir. Using grep like:

grep -rn "on\ .*do " apps/*

we get:

#...
apps/app.rb:10:              on put, ':id/edit' do |id|
apps/app.rb:14:              on ':id/configuration' do |id|
apps/app.rb:24:                 on put, param(:data) do |data|
apps/app.rb:44:                 on post, param(:data) do |data|
apps/app.rb:50:                 on put, ':id/recover' do |id|
#...

Not as fancy as rake routes, but definetely faster :P

soveran commented 8 years ago

I'm closing this issue, but I recommend reading this thread: https://github.com/soveran/syro/issues/18