Hey, here’s two rake tasks I’ve been hoarding. I thought I’d pass them along.
rake routes
Wanna see all your routes right there in your terminal? Yeah.
desc "Print out all the currently defined routes." task :routes => :environment do puts ActionController::Routing::Routes.routes.map { |r| sprintf "%30s => %s", r.path.inspect, r.known.inspect } rescue puts ActionController::Routing::Routes.routes end
Stick that in RAILS_ROOT/lib/tasks/ as something like routes.rake, then run it with rake routes. You’ll get output like this:
ANY /:controller/service.wsdl/ {:action=>"wsdl"} GET /posts/ {:controller=>"posts", :action=>"index"} GET /posts.:format/ {:controller=>"posts", :action=>"index"} POST /posts/ {:controller=>"posts", :action=>"create"} POST /posts.:format/ {:controller=>"posts", :action=>"create"} GET /posts/new/ {:controller=>"posts", :action=>"new"} GET /posts/new.:format/ {:controller=>"posts", :action=>"new"} GET /posts/:id;edit/ {:controller=>"posts", :action=>"edit"} GET /posts/:id.:format;edit/ {:controller=>"posts", :action=>"edit"} GET /posts/:id/ {:controller=>"posts", :action=>"show"} GET /posts/:id.:format/ {:controller=>"posts", :action=>"show"} PUT /posts/:id/ {:controller=>"posts", :action=>"update"} PUT /posts/:id.:format/ {:controller=>"posts", :action=>"update"} DELETE /posts/:id/ {:controller=>"posts", :action=>"destroy"} DELETE /posts/:id.:format/ {:controller=>"posts", :action=>"destroy"} ANY /:controller/:action/:id/ {}
Works with edge and 1.1.6. Yeah! They just, erm, look kinda different.
rake pistoned
You’re using piston to manage your plugins (or other code originating from alien repositories), right? I couldn’t find a way to say “show me all the directories piston is managing,” so I created a way.
desc "Print directories managed by Piston." task :pistoned do puts Dir['**/.svn/dir-props'].select { |file| File.read(file) =~ /piston/ }.map { |file| file.split('.svn').first } end
Stick that in RAILS_ROOT/lib/tasks/ then run rake pistoned to see which directories are under piston’s love and care. Something like this:
vendor/plugins/acts_as_attachment/ vendor/plugins/acts_as_textiled/ vendor/plugins/has_many_polymorphs/ vendor/plugins/rspec/ vendor/plugins/shared/acts_as_cached/ vendor/plugins/shared/microformat_helper/ vendor/plugins/shared/mofo/
Other rake goodness, like chaining tasks, can be found in a previous post.
Update: hasmanyjosh whipped up a revised version of rake routes which also prints the names. Check it out. Edge only.
Printing the routes can be this easy:
desc “Print out all the currently defined routes.” task :routes => :environment do puts ActionController::Routing::Routes.routes end
Or does this not print something you added?
Instead of depending on the working copy file format, why not make Subversion work for you ?
svn propget—recursive piston:root
Jay: That only works on edge, not 1.1.6.
François: I’d love to leverage svn, but I’m not that great at it. Here’s the issue: I have vendor/plugins/shared which is svn:external. If I run your svn propget command, it only works for the current repository—it doesn’t show me information pistoned directories within my externals. Any ideas?
Can you turn the routes task into a patch for Rails, submit it and see if the core time wants to include it in the next release? I really think it’s a handy little task that should just be in there by default! :-)
Piston 1.2.1 now has the status subcommand, which shows the status of your working copy. Looking at the implementation, the use case you have is not covered either. I use svn pg—recursive under the covers. Try “piston status vendor/plugins/shared/*”
Here is an Update from rails 2.0.2
rake routes is included !!
Here is the output which will be ugly here…
best to pipe the rake output to a file formatted_edit_song_content GET /songs/:song_id/contents/:id/edit.:format {:controller=>”contents”, :action=>”edit”} song_content GET /songs/:song_id/contents/:id {:controller=>”contents”, :action=>”show”} formatted_song_content GET /songs/:song_id/contents/:id.:format {:controller=>”contents”, :action=>”show”} PUT /songs/:song_id/contents/:id {:controller=>”contents”, :action=>”update”} PUT /songs/:song_id/contents/:id.:format {:controller=>”contents”, :action=>”update”} DELETE /songs/:song_id/contents/:id {:controller=>”contents”, :action=>”destroy”} DELETE /songs/:song_id/contents/:id.:format {:controller=>”contents”, :action=>”destroy”} root / {:controller=>”content”, :action=>”index”} /:controller/:action/:id Showing all Routes - / - /songs/ - /songs.:format/ - /songs/ - /songs.:format/ - /songs/new/ - /songs/new.:format/ - /songs/:id/edit/ - /songs/:id/edit.:format/ - /songs/:id/ - /songs/:id.:format/ - /songs/:id/ - /songs/:id.:format/ - /songs/:id/ - /songs/:id.:format/ - /songs/:song_id/contents/ - /songs/:song_id/contents.:format/ - /songs/:song_id/contents/ - /songs/:song_id/contents.:format/ - /songs/:song_id/contents/new/ - /songs/:song_id/contents/new.:format/ - /songs/:song_id/contents/:id/edit/ - /songs/:song_id/contents/:id/edit.:format/ - /songs/:song_id/contents/:id/ - /songs/:song_id/contents/:id.:format/ - /songs/:song_id/contents/:id/ - /songs/:song_id/contents/:id.:format/ - /songs/:song_id/contents/:id/ - /songs/:song_id/contents/:id.:format/ - /
Chime in.