Created
November 9, 2008 10:54
Revisions
-
methodmissing created this gist
Nov 9, 2008 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ class RouteFilter class << self def routes ActionController::Routing::Routes.routes end def controllers ::Object.subclasses_of( ::ActionController::Base ) end def prune! controllers.each do |controller| puts "** Pruning routes for #{controller.to_s}" new( controller ).prune! end end end attr_accessor :controller def initialize( controller ) @controller = controller end def path @controller.controller_path end def routes @routes ||= self.class.routes.find_all{|r| r.requirements[:controller] == path } end def routeable_actions @actions_from_routes ||= @routes.map{|r| r.requirements[:action] }.to_set end def defined_actions @defined_actions ||= @controller.action_methods end def pruneable_actions @pruneable_actions ||= routeable_actions ^ defined_actions end def pruneable_routes routes.find_all{|r| pruneable_actions.include?( r.requirements[:action] ) } end def prune! pruneable_routes.each do |pruneable| RouteFilter.routes.delete(pruneable) end end end