Skip to content

Instantly share code, notes, and snippets.

@naoty
Created October 4, 2012 05:51
Show Gist options
  • Save naoty/3831688 to your computer and use it in GitHub Desktop.
Save naoty/3831688 to your computer and use it in GitHub Desktop.
Print out defined routes into csv
require 'csv'
namespace :routes do
desc 'Print out defined routes into csv, with TARGET and PATTERN'
task :csv do |task|
routes_task = Rake::Task['routes'].invoke.first
routes = routes_task.call
target = ENV['TARGET'] || 'tmp/routes.csv'
CSV.open(target, 'wb') do |csv|
csv << ['name', 'verb', 'path']
routes.each do |route|
next if ENV['PATTERN'] && !route[:path].include?(ENV['PATTERN'])
csv << [route[:name], route[:verb], route[:path]]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment