lib/hanami/router.rb in hanami-router-2.0.0.beta4 vs lib/hanami/router.rb in hanami-router-2.0.0.rc1

- old
+ new

@@ -1,17 +1,18 @@ # frozen_string_literal: true require "rack" require "rack/utils" +# @see Hanami::Router module Hanami # Rack compatible, lightweight and fast HTTP Router. # # @since 0.1.0 class Router require "hanami/router/version" - require "hanami/router/error" + require "hanami/router/errors" require "hanami/router/segment" require "hanami/router/redirect" require "hanami/router/prefix" require "hanami/router/params" require "hanami/router/trie" @@ -351,10 +352,12 @@ # @param path [String] the relative URL to be matched # @param to [#call] the Rack endpoint # @param as [Symbol] a unique name for the route # @param code [Integer] a HTTP status code to use for the redirect # + # @raise [Hanami::Router::UnknownHTTPStatusCodeError] when an unknown redirect code is given + # # @since 0.1.0 # # @see #get # @see #initialize def redirect(path, to: nil, as: nil, code: DEFAULT_REDIRECT_CODE) @@ -432,11 +435,11 @@ # # @param name [Symbol] the route name # # @return [String] # - # @raise [Hanami::Routing::InvalidRouteException] when the router fails to + # @raise [Hanami::Router::MissingRouteError] when the router fails to # recognize a route, because of the given arguments. # # @since 0.1.0 # # @see #url @@ -462,11 +465,11 @@ # # @param name [Symbol] the route name # # @return [String] # - # @raise [Hanami::Routing::InvalidRouteException] when the router fails to + # @raise [Hanami::Router::MissingRouteError] when the router fails to # recognize a route, because of the given arguments. # # @since 0.1.0 # # @see #path @@ -594,16 +597,15 @@ # route.verb # => "POST" # route.routable? # => false # route.params # => {:id=>"1"} def recognize(env, params = {}, options = {}) require "hanami/router/recognized_route" + env = env_for(env, params, options) endpoint, params = lookup(env) - RecognizedRoute.new( - endpoint, _params(env, params) - ) + RecognizedRoute.new(endpoint, _params(env, params)) end # @since 2.0.0 # @api private def fixed(env) @@ -684,11 +686,11 @@ ::Rack::MockRequest.env_for(env, options) when ::Symbol begin url = path(env, params) return env_for(url, params, options) # rubocop:disable Style/RedundantReturn - rescue Hanami::Router::InvalidRouteException + rescue Hanami::Router::MissingRouteError {} # Empty Rack env end else env end @@ -797,11 +799,14 @@ add_variable_route(http_method, path, endpoint, constraints) else add_fixed_route(http_method, path, endpoint) end - add_named_route(path, as, constraints) if as + if as + as = prefixed_name(as) + add_named_route(path, as, constraints) + end if inspect? @inspector.add_route( Route.new( http_method: http_method, path: path, to: to || endpoint, as: as, constraints: constraints, blk: blk @@ -841,10 +846,10 @@ end # @since 2.0.0 # @api private def add_named_route(path, as, constraints) - @url_helpers.add(prefixed_name(as), Segment.fabricate(path, **constraints)) + @url_helpers.add(as, Segment.fabricate(path, **constraints)) end # @since 2.0.0 # @api private def variable?(path)