Created
June 17, 2020 22:00
-
-
Save MiguelSavignano/46e834c57e19e5bb1fd6819d7c180f9d to your computer and use it in GitHub Desktop.
Routes to CSV, rails runner get_routes.rb
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
class CSVFormatter | |
def initialize | |
@buffer = [] | |
end | |
def result | |
@buffer.join("\n") | |
end | |
def section_title(title) | |
end | |
def section(routes) | |
routes.map do |r| | |
if filter(r) | |
@buffer << "#{ verb(r)};#{r[:path]};#{r[:reqs]};#{r[:name]}" | |
end | |
end | |
end | |
def header(routes) | |
@buffer << 'Verb;URL;ControllerAction;Prefix' | |
end | |
def no_routes | |
@buffer << <<-MESSAGE.strip_heredoc | |
You don't have any routes defined! | |
Please add some routes in config/routes.rb. | |
For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html. | |
MESSAGE | |
end | |
private | |
def filter(route) | |
route[:path] =~ /\/api\/v3/ | |
end | |
def verb(route) | |
route[:verb].presence || "GET" | |
end | |
end | |
all_routes = Rails.application.routes.routes | |
require 'action_dispatch/routing/inspector' | |
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes) | |
# puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, ENV['CONTROLLER']) | |
puts inspector.format(CSVFormatter.new, ENV['CONTROLLER']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment