Class: Hanami::Routes Private
- Inherits:
-
Object
- Object
- Hanami::Routes
- Defined in:
- lib/hanami/routes.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Routes factory
A Hanami application has this factory instantiated by default and associated to the ‘Routes` constant, under the application namespace.
Instance Method Summary collapse
-
#initialize(routes) ⇒ Hanami::Routes
constructor
private
Initialize the factory.
-
#path(name, *args) ⇒ Hanami::Utils::Escape::SafeString
private
Return a relative path for the given route name.
-
#recognize(env) ⇒ Hanami::Routing::RecognizedRoute
private
Recognize a route from a Rack env.
-
#url(name, *args) ⇒ Hanami::Utils::Escape::SafeString
private
Return an absolute path for the given route name.
Constructor Details
#initialize(routes) ⇒ Hanami::Routes
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.
Initialize the factory
20 21 22 |
# File 'lib/hanami/routes.rb', line 20 def initialize(routes) @routes = routes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object (protected)
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.
209 210 211 212 213 214 215 216 217 |
# File 'lib/hanami/routes.rb', line 209 def method_missing(m, *args) named_route, type = m.to_s.split(/\_(path|url)\z/) if type public_send(type, named_route.to_sym, *args) else super end end |
Instance Method Details
#path(name, *args) ⇒ Hanami::Utils::Escape::SafeString
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.
Return a relative path for the given route name
75 76 77 |
# File 'lib/hanami/routes.rb', line 75 def path(name, *args) Utils::Escape::SafeString.new(@routes.path(name, *args)) end |
#recognize(env) ⇒ 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.
Recognize a route from a Rack env.
This method is designed for testing purposes
201 202 203 |
# File 'lib/hanami/routes.rb', line 201 def recognize(env) @routes.recognize(env) end |
#url(name, *args) ⇒ Hanami::Utils::Escape::SafeString
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.
Return an absolute path for the given route name
136 137 138 |
# File 'lib/hanami/routes.rb', line 136 def url(name, *args) Utils::Escape::SafeString.new(@routes.url(name, *args)) end |