Skip to content

Instantly share code, notes, and snippets.

@tmarkiewicz
Forked from hardbap/routes.rake
Created August 15, 2009 19:19
Show Gist options
  • Select an option

  • Save tmarkiewicz/168430 to your computer and use it in GitHub Desktop.

Select an option

Save tmarkiewicz/168430 to your computer and use it in GitHub Desktop.

Revisions

  1. @hardbap hardbap renamed this gist Jul 21, 2009. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions gistfile1.txt → routes.rake
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    desc 'Print out all defined routes in match order, with names.'
    desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
    task :routes => :environment do
    all_routes = ENV['CONTROLLER'].blank? ? ActionController::Routing::Routes.routes : ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] }

    all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
    routes = all_routes.collect do |route|
    name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
    verb = route.conditions[:method].to_s.upcase
    @@ -16,4 +15,4 @@ task :routes => :environment do
    routes.each do |r|
    puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
    end
    end
    end
  2. @hardbap hardbap created this gist Jul 20, 2009.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    desc 'Print out all defined routes in match order, with names.'
    task :routes => :environment do
    all_routes = ENV['CONTROLLER'].blank? ? ActionController::Routing::Routes.routes : ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] }

    routes = all_routes.collect do |route|
    name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
    verb = route.conditions[:method].to_s.upcase
    segs = route.segments.inject("") { |str,s| str << s.to_s }
    segs.chop! if segs.length > 1
    reqs = route.requirements.empty? ? "" : route.requirements.inspect
    {:name => name, :verb => verb, :segs => segs, :reqs => reqs}
    end
    name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
    verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
    segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max
    routes.each do |r|
    puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
    end
    end