Class: Lotus::Routing::RoutesInspector
- Inherits:
-
Object
- Object
- Lotus::Routing::RoutesInspector
- Defined in:
- lib/lotus/routing/routes_inspector.rb
Overview
Routes inspector
Constant Summary collapse
- FORMATTER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default route formatter
"%<name>20s %<methods>-10s %<path>-30s %<endpoint>-30s\n".freeze
- HTTP_METHODS_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default HTTP methods separator
', '.freeze
- INSPECTOR_HEADER_HASH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default inspector header hash values
Hash[ name: 'Name', methods: 'Method', path: 'Path', endpoint: 'Action' ].freeze
- INSPECTOR_HEADER_NAME =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default inspector header name values
'Name'.freeze
- EMPTY_LINE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Empty line string
"\n".freeze
Instance Method Summary collapse
-
#initialize(routes) ⇒ Lotus::Routing::RoutesInspector
constructor
private
Instantiate a new inspector.
-
#inspect_routes(formatter, base_path) ⇒ String
private
Returns a string representation of routes.
-
#to_s(formatter = FORMATTER, base_path = nil) ⇒ String
Return a formatted string that describes all the routes.
Constructor Details
#initialize(routes) ⇒ Lotus::Routing::RoutesInspector
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiate a new inspector
50 51 52 |
# File 'lib/lotus/routing/routes_inspector.rb', line 50 def initialize(routes) @routes = routes end |
Instance Method Details
#inspect_routes(formatter, base_path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a string representation of routes
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/lotus/routing/routes_inspector.rb', line 155 def inspect_routes(formatter, base_path) result = '' # TODO refactoring: replace conditional with polymorphism # We're exposing too much knowledge from Routing::Route: # #path_for_generation and #base_path @routes.each do |route| result << if router = route.nested_router inspect_router(formatter, router, route, base_path) else inspect_route(formatter, route, base_path) end end result end |
#to_s(formatter = FORMATTER, base_path = nil) ⇒ String
Return a formatted string that describes all the routes
136 137 138 139 140 141 |
# File 'lib/lotus/routing/routes_inspector.rb', line 136 def to_s(formatter = FORMATTER, base_path = nil) base_path = Utils::PathPrefix.new(base_path) inspect_routes(formatter, base_path) .insert(0, formatter % INSPECTOR_HEADER_HASH + EMPTY_LINE) end |