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 = {})
- #filter_routes(routes, filter) private
- #format_routes(formatter, filter, engine_name, routes) private
- #load_engines_routes private
- #normalize_filter(filter) private
- #wrap_routes(routes) private
Constructor Details
.new(routes) ⇒ RoutesInspector
# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 82
def initialize(routes) @routes = wrap_routes(routes) @engines = load_engines_routes end
Instance Method Details
#filter_routes(routes, filter) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 147
def filter_routes(routes, filter) if filter routes.select do |route| filter.any? { |filter_type, value| route.matches_filter?(filter_type, value) } end else routes end end
#format(formatter, filter = {})
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 87
def format(formatter, filter = {}) all_routes = { nil => @routes }.merge(@engines) all_routes.each do |engine_name, routes| format_routes(formatter, filter, engine_name, routes) end formatter.result end
#format_routes(formatter, filter, engine_name, routes) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 98
def format_routes(formatter, filter, engine_name, routes) routes = filter_routes(routes, normalize_filter(filter)).map(&:to_h) formatter.section_title "Routes for #{engine_name || "application"}" if @engines.any? if routes.any? formatter.header routes formatter.section routes else formatter.no_routes engine_name, routes, filter end formatter. routes end
#load_engines_routes (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 115
def load_engines_routes engine_routes = @routes.select(&:engine?) engines = engine_routes.to_h do |engine_route| engine_app_routes = engine_route.rack_app.routes engine_app_routes = engine_app_routes.routes if engine_app_routes.is_a?(ActionDispatch::Routing::RouteSet) [engine_route.endpoint, wrap_routes(engine_app_routes)] end engines end
#normalize_filter(filter) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 128
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
#wrap_routes(routes) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/inspector.rb', line 111
def wrap_routes(routes) routes.routes.map { |route| RouteWrapper.new(route) }.reject(&:internal?) end