Created
August 10, 2010 11:52
-
-
Save astropanic/517137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Print out all unused routes' | |
task :unused => :environment do | |
all_routes = 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 | |
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| | |
controller, action = r[:reqs].scan(/"\b([_A-Za-z]+)\b/) | |
next if controller.blank? or action.blank? | |
action = action.to_s | |
controller = "#{controller}_controller".camelcase.constantize | |
if !controller.public_instance_methods.include?(action) | |
puts "#{controller}##{action}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment