class ActionDispatch::Routing::RoutesInspector
:nodoc:
People should not use this class.
executes ‘bin/rails routes` or looks at the RoutingError page.
This class is just used for displaying route information when someone
#
def collect_engine_routes(route)
def collect_engine_routes(route) name = route.endpoint return unless route.engine? return if @engines[name] routes = route.rack_app.routes if routes.is_a?(ActionDispatch::Routing::RouteSet) @engines[name] = collect_routes(routes.routes) end end
def collect_routes(routes)
def collect_routes(routes) routes.collect do |route| RouteWrapper.new(route) end.reject(&:internal?).collect do |route| collect_engine_routes(route) { name: route.name, verb: route.verb, path: route.path, reqs: route.reqs, source_location: route.source_location } end end
def filter_routes(filter)
def filter_routes(filter) if filter @routes.select do |route| route_wrapper = RouteWrapper.new(route) filter.any? { |filter_type, value| route_wrapper.matches_filter?(filter_type, value) } end else @routes end end
def format(formatter, filter = {})
def format(formatter, filter = {}) routes_to_display = filter_routes(normalize_filter(filter)) routes = collect_routes(routes_to_display) if routes.none? formatter.no_routes(collect_routes(@routes), filter) return formatter.result end formatter.header routes formatter.section routes @engines.each do |name, engine_routes| formatter.section_title "Routes for #{name}" formatter.section engine_routes end formatter.result end
def initialize(routes)
People should not use this class.
executes `bin/rails routes` or looks at the RoutingError page.
This class is just used for displaying route information when someone
#
def initialize(routes) @engines = {} @routes = routes end
def normalize_filter(filter)
def normalize_filter(filter) if filter[:controller] { controller: /#{filter[:controller].underscore.sub(/_?controller\z/, "")}/ } elsif filter[:grep] grep_pattern = Regexp.new(filter[:grep]) path = URI::DEFAULT_PARSER.escape(filter[:grep]) normalized_path = ("/" + path).squeeze("/") { controller: grep_pattern, action: grep_pattern, verb: grep_pattern, name: grep_pattern, path: grep_pattern, exact_path_match: normalized_path, } end end