Class: Lotus::Routing::RecognizedRoute
- Inherits:
-
Object
- Object
- Lotus::Routing::RecognizedRoute
- Defined in:
- lib/lotus/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
- 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) ⇒ Lotus::Routing::RecognizedRoute
constructor
private
Creates a new instance.
-
#routable? ⇒ TrueClass, FalseClass
Check if routable.
-
#verb ⇒ String
HTTP verb (aka method).
Constructor Details
#initialize(response, env, router) ⇒ Lotus::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
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lotus/routing/recognized_route.rb', line 41 def initialize(response, env, router) @env = env 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)
29 30 31 |
# File 'lib/lotus/routing/recognized_route.rb', line 29 def params @params end |
Instance Method Details
#action ⇒ String
Action name
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/lotus/routing/recognized_route.rb', line 101 def action namespace = NAMESPACE % @namespace if destination.match(namespace) Lotus::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
66 67 68 69 70 71 72 |
# File 'lib/lotus/routing/recognized_route.rb', line 66 def call(env) if routable? @endpoint.call(env) else raise Lotus::Router::NotRoutableEndpointError.new(@env) end end |
#routable? ⇒ TrueClass, FalseClass
Check if routable
131 132 133 |
# File 'lib/lotus/routing/recognized_route.rb', line 131 def routable? !!@endpoint end |
#verb ⇒ String
HTTP verb (aka method)
80 81 82 |
# File 'lib/lotus/routing/recognized_route.rb', line 80 def verb @env[REQUEST_METHOD] end |