Err the Blog Atom Feed Icon
Err the Blog
Rubyisms and Railities
  • “Rakie Pankie”
    – Chris on November 15, 2006

    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.

  • Jay Fields, about 7 hours later:

    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?

  • François Beausoleil, about 7 hours later:

    Instead of depending on the working copy file format, why not make Subversion work for you ?

    svn propget—recursive piston:root

  • Chris, about 8 hours later:

    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?

  • Thijs van der Vossen, about 15 hours later:

    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! :-)

  • François Beausoleil, 22 days later:

    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/*”

  • bartee, about 1 year later:

    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/ - /

    /                                         {:controller=>"songs", :action=>"index"}
                         songs GET    /songs                                    {:controller=>"songs", :action=>"index"}
               formatted_songs GET    /songs.:format                            {:controller=>"songs", :action=>"index"}
                               POST   /songs                                    {:controller=>"songs", :action=>"create"}
                               POST   /songs.:format                            {:controller=>"songs", :action=>"create"}
                      new_song GET    /songs/new                                {:controller=>"songs", :action=>"new"}
            formatted_new_song GET    /songs/new.:format                        {:controller=>"songs", :action=>"new"}
                     edit_song GET    /songs/:id/edit                           {:controller=>"songs", :action=>"edit"}
           formatted_edit_song GET    /songs/:id/edit.:format                   {:controller=>"songs", :action=>"edit"}
                          song GET    /songs/:id                                {:controller=>"songs", :action=>"show"}
                formatted_song GET    /songs/:id.:format                        {:controller=>"songs", :action=>"show"}
                               PUT    /songs/:id                                {:controller=>"songs", :action=>"update"}
                               PUT    /songs/:id.:format                        {:controller=>"songs", :action=>"update"}
                               DELETE /songs/:id                                {:controller=>"songs", :action=>"destroy"}
                               DELETE /songs/:id.:format                        {:controller=>"songs", :action=>"destroy"}
                 song_contents GET    /songs/:song_id/contents                  {:controller=>"contents", :action=>"index"}
       formatted_song_contents GET    /songs/:song_id/contents.:format          {:controller=>"contents", :action=>"index"}
                               POST   /songs/:song_id/contents                  {:controller=>"contents", :action=>"create"}
                               POST   /songs/:song_id/contents.:format          {:controller=>"contents", :action=>"create"}
              new_song_content GET    /songs/:song_id/contents/new              {:controller=>"contents", :action=>"new"}
    formatted_new_song_content GET    /songs/:song_id/contents/new.:format      {:controller=>"contents", :action=>"new"}
             edit_song_content GET    /songs/:song_id/contents/:id/edit         {:controller=>"contents", :action=>"edit"}
  • Six people have commented.
    Chime in.
    Sorry, no more comments :(
This is Err, the weblog of PJ Hyett and Chris Wanstrath.
All original content copyright ©2006-2008 the aforementioned.