lib/hanami/routing/routes_inspector.rb in hanami-router-1.3.2 vs lib/hanami/routing/routes_inspector.rb in hanami-router-2.0.0.alpha1
- old
+ new
@@ -1,47 +1,49 @@
-require 'hanami/utils/path_prefix'
+# frozen_string_literal: true
+require "hanami/utils/path_prefix"
+
module Hanami
module Routing
# Routes inspector
#
# @since 0.2.0
class RoutesInspector
# Default route formatter
#
# @since 0.2.0
# @api private
- FORMATTER = "%<name>20s %<methods>-10s %<path>-30s %<endpoint>-30s\n".freeze
+ FORMATTER = "%<name>20s %<methods>-10s %<path>-30s %<endpoint>-30s\n"
# Default HTTP methods separator
#
# @since 0.2.0
# @api private
- HTTP_METHODS_SEPARATOR = ', '.freeze
+ HTTP_METHODS_SEPARATOR = ", "
# Default inspector header hash values
#
# @since 0.5.0
# @api private
- INSPECTOR_HEADER_HASH = Hash[
- name: 'Name',
- methods: 'Method',
- path: 'Path',
- endpoint: 'Action'
+ INSPECTOR_HEADER_HASH = ::Hash[
+ name: "Name",
+ methods: "Method",
+ path: "Path",
+ endpoint: "Action"
].freeze
# Default inspector header name values
#
# @since 0.5.0
# @api private
- INSPECTOR_HEADER_NAME = 'Name'.freeze
+ INSPECTOR_HEADER_NAME = "Name"
# Empty line string
#
# @since 0.5.0
# @api private
- EMPTY_LINE = "\n".freeze
+ EMPTY_LINE = "\n"
# Instantiate a new inspector
#
# @return [Hanami::Routing::RoutesInspector] the new instance
#
@@ -153,21 +155,21 @@
# @api private
#
# @see Hanami::Routing::RoutesInspector#FORMATTER
# @see Hanami::Routing::RoutesInspector#to_s
def inspect_routes(formatter, base_path)
- result = ''
+ result = ""
- # TODO refactoring: replace conditional with polymorphism
+ # 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
+ result << if (router = route.nested_router)
+ inspect_router(formatter, router, route, base_path)
+ else
+ inspect_route(formatter, route, base_path)
+ end
end
result
end
@@ -190,12 +192,12 @@
#
# @see Hanami::Routing::RoutesInspector#FORMATTER
# @see Hanami::Routing::RoutesInspector#to_s
def inspect_route(formatter, route, base_path)
formatter % Hash[
- name: route.name,
- methods: route.request_methods.to_a.join(HTTP_METHODS_SEPARATOR),
- path: base_path.join(route.path_for_generation),
+ name: route.name,
+ methods: route.request_methods.to_a.join(HTTP_METHODS_SEPARATOR),
+ path: base_path.join(route.path_for_generation),
endpoint: route.dest.inspect
]
end
# Returns a string representation of the given router