Class: Hanami::Routing::RecognizedRoute
- Inherits:
-
Object
- Object
- Hanami::Routing::RecognizedRoute
- Defined in:
- lib/hanami/routing/recognized_route.rb
Overview
Represents a result of router path recognition.
Constant Summary collapse
- REQUEST_METHOD =
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.
'REQUEST_METHOD'.freeze
- PATH_INFO =
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.
'PATH_INFO'.freeze
- NAMESPACE =
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.
'%s::'.freeze
- NAMESPACE_REPLACEMENT =
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.
''.freeze
- ACTION_PATH_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.
'/'.freeze
Instance Attribute Summary collapse
- #params ⇒ Object readonly
Instance Method Summary collapse
-
#action ⇒ String
Action name.
-
#call(env) ⇒ Array
Rack protocol compatibility.
-
#initialize(response, env, router) ⇒ Hanami::Routing::RecognizedRoute
constructor
private
Creates a new instance.
-
#path ⇒ String
Relative URL (path).
-
#routable? ⇒ TrueClass, FalseClass
Check if routable.
-
#verb ⇒ String
HTTP verb (aka method).
Constructor Details
#initialize(response, env, router) ⇒ Hanami::Routing::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.
Creates a new instance
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hanami/routing/recognized_route.rb', line 45 def initialize(response, env, router) @env = env @endpoint = nil @params = {} unless response.nil? @endpoint = response.route.dest @params = response.params end @namespace = router.namespace @action_separator = router.action_separator end |
Instance Attribute Details
#params ⇒ Object (readonly)
33 34 35 |
# File 'lib/hanami/routing/recognized_route.rb', line 33 def params @params end |
Instance Method Details
#action ⇒ String
Action name
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/hanami/routing/recognized_route.rb', line 117 def action return unless routable? namespace = NAMESPACE % @namespace if destination.match(namespace) Hanami::Utils::String.new( destination.sub(namespace, NAMESPACE_REPLACEMENT) ).underscore.rsub(ACTION_PATH_SEPARATOR, @action_separator) else destination end end |
#call(env) ⇒ Array
Rack protocol compatibility
72 73 74 75 76 77 78 |
# File 'lib/hanami/routing/recognized_route.rb', line 72 def call(env) if routable? @endpoint.call(env) else raise Hanami::Router::NotRoutableEndpointError.new(@env) end end |
#path ⇒ String
Relative URL (path)
96 97 98 |
# File 'lib/hanami/routing/recognized_route.rb', line 96 def path @env[PATH_INFO] end |
#routable? ⇒ TrueClass, FalseClass
Check if routable
148 149 150 |
# File 'lib/hanami/routing/recognized_route.rb', line 148 def routable? @endpoint&.routable? end |
#verb ⇒ String
HTTP verb (aka method)
86 87 88 |
# File 'lib/hanami/routing/recognized_route.rb', line 86 def verb @env[REQUEST_METHOD] end |