Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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