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
namespace :routes do | |
desc 'Print out all defined routes in match order, with names, per constraint class. Target specific constraint class with CONSTRAINT=x. Target specific controller with CONTROLLER=x.' | |
task constrained: :environment do | |
Rails.application.reload_routes! | |
constraints_routes = Hash.new | |
Rails.application.routes.routes.each do |route| | |
group = (route.app.class == ActionDispatch::Routing::Mapper::Constraints ? route.app.send( :constraints ).first.to_s : 'No constraint class') | |
constraints_routes[group] ||= [] |