Last active
August 26, 2019 14:48
-
-
Save YurySolovyov/682c35ffabecc56fe5528075a4577567 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module ActionDispatch | |
module Routing | |
class HashFormatter | |
attr_reader :result | |
def initialize | |
@result = {} | |
end | |
def section_title(title); end | |
def section(routes) | |
routes.each { |route| incorporate_route(route) } | |
end | |
def header(routes); end | |
def no_routes(routes, filter); end | |
private | |
def incorporate_route(route) | |
name = route[:name] | |
return if route.empty? || name.empty? | |
prepared_route = route.without(:reqs, :name).merge( | |
path: route[:path].remove('(.:format)') | |
) | |
result.merge!(name => prepared_route) | |
end | |
end | |
end | |
end |
This file contains hidden or 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
require 'action_dispatch/routing/inspector' | |
module ApplicationHelper | |
def client_routes_json | |
inspector = ActionDispatch::Routing::RoutesInspector.new( | |
Rails.application.routes.routes | |
) | |
inspector.format(ActionDispatch::Routing::HashFormatter.new).to_json | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment