Sha256: 9c451fcaea711163476953c87b659c9695cd87ee010cdebc1334b5d4bcbf66f6

Contents?: true

Size: 1.34 KB

Versions: 9

Compression:

Stored size: 1.34 KB

Contents

desc 'Print out all defined routes in match order, with names.'

# borrowed from eugenebolshakov / override_rake_task, wish this was a gem!
Rake::TaskManager.class_eval do
  def remove_task(task_name)
    @tasks.delete(task_name.to_s)
  end
end
 
def remove_task(task_name)
  Rake.application.remove_task(task_name)
end
 
def override_task(args, &block)
  name, deps = Rake.application.resolve_args([args])  
  remove_task Rake.application[name].name
  task(args, &block)
end

override_task :routes => :environment do
  routes = ActionController::Routing::Routes.routes.collect do |route|
    name = route.named.to_s
    verb = route.conditions && route.conditions[:method].to_s.upcase || ''
    path = route.original_path
    reqs = route.requirements.blank? ? "" : route.requirements.inspect
    dests = route.destination.inspect
    {:name => name, :verb => verb, :path => path, :reqs => reqs, :dests => dests}
  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
  path_width = routes.collect {|r| r[:path]}.collect {|s| s.length}.max
  dests_width = routes.collect {|r| r[:dests]}.collect {|s| s.length}.max
  routes.each do |r|
    puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}  #{r[:dests]}"
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
usher-0.8.3 tasks/routes.rake
usher-0.8.2 tasks/routes.rake
usher-0.8.1 tasks/routes.rake
usher-0.8.0 tasks/routes.rake
usher-0.7.5 tasks/routes.rake
usher-0.7.4 tasks/routes.rake
usher-0.7.3 tasks/routes.rake
usher-0.7.2 tasks/routes.rake
usher-0.7.1 tasks/routes.rake