Class: Hanami::Router::RecognizedRoute
- Inherits:
-
Object
- Object
- Hanami::Router::RecognizedRoute
- Defined in:
- lib/hanami/router/recognized_route.rb
Overview
Represents a result of router path recognition.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Rack protocol compatibility.
-
#endpoint ⇒ Object?
Returns the route’s endpoint object.
-
#initialize(endpoint, env) ⇒ RecognizedRoute
constructor
private
A new instance of RecognizedRoute.
-
#params ⇒ Hash
Returns the route’s path params.
-
#path ⇒ String
Relative URL (path).
-
#redirect? ⇒ Boolean
Returns true if the route is a redirect.
-
#redirection_path ⇒ String?
Returns the route’s redirect path, if it is a redirect, or nil otherwise.
-
#routable? ⇒ Boolean
Returns true if the route has an #endpoint.
-
#verb ⇒ String
HTTP verb (aka method).
Constructor Details
#initialize(endpoint, env) ⇒ RecognizedRoute
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 new instance of RecognizedRoute.
14 15 16 17 |
# File 'lib/hanami/router/recognized_route.rb', line 14 def initialize(endpoint, env) @endpoint = endpoint @env = env end |
Instance Method Details
#call(env) ⇒ Array
Rack protocol compatibility
32 33 34 35 36 37 38 |
# File 'lib/hanami/router/recognized_route.rb', line 32 def call(env) if routable? @endpoint.call(env) else raise NotRoutableEndpointError.new(@env) end end |
#endpoint ⇒ Object?
Returns the route’s endpoint object.
Returns nil if the route is a redirect.
78 79 80 81 82 |
# File 'lib/hanami/router/recognized_route.rb', line 78 def endpoint return nil if redirect? @endpoint end |
#params ⇒ Hash
Returns the route’s path params.
66 67 68 |
# File 'lib/hanami/router/recognized_route.rb', line 66 def params @env[Router::PARAMS] end |
#path ⇒ String
Relative URL (path)
56 57 58 |
# File 'lib/hanami/router/recognized_route.rb', line 56 def path @env[::Rack::PATH_INFO] end |
#redirect? ⇒ Boolean
Returns true if the route is a redirect.
100 101 102 |
# File 'lib/hanami/router/recognized_route.rb', line 100 def redirect? @endpoint.is_a?(Redirect) end |
#redirection_path ⇒ String?
Returns the route’s redirect path, if it is a redirect, or nil otherwise.
110 111 112 113 114 |
# File 'lib/hanami/router/recognized_route.rb', line 110 def redirection_path return nil unless redirect? @endpoint.destination end |
#routable? ⇒ Boolean
Returns true if the route has an #endpoint.
90 91 92 |
# File 'lib/hanami/router/recognized_route.rb', line 90 def routable? !@endpoint.nil? end |
#verb ⇒ String
HTTP verb (aka method)
46 47 48 |
# File 'lib/hanami/router/recognized_route.rb', line 46 def verb @env[::Rack::REQUEST_METHOD] end |