Class: ActionDispatch::Routing::RoutesInspector
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | actionpack/lib/action_dispatch/routing/inspector.rb |
Overview
This class is just used for displaying route information when someone executes bin/rails routes
or looks at the RoutingError page. People should not use this class.
Class Method Summary
- .new(routes) ⇒ RoutesInspector constructor
Instance Method Summary
- #format(formatter, filter = {})
- #collect_engine_routes(route) private
- #collect_routes(routes) private
- #filter_routes(filter) private
- #normalize_filter(filter) private
Constructor Details
.new(routes) ⇒ RoutesInspector
# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 74
def initialize(routes) @engines = {} @routes = routes end
Instance Method Details
#collect_engine_routes(route) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 143
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
#collect_routes(routes) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 129
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
#filter_routes(filter) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 118
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
#format(formatter, filter = {})
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 79
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
#normalize_filter(filter) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 99
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::RFC2396_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