Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created November 9, 2008 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save methodmissing/23253 to your computer and use it in GitHub Desktop.
Save methodmissing/23253 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment