Class: Cubic::Router
- Inherits:
-
Object
- Object
- Cubic::Router
- Defined in:
- lib/cubic/router.rb
Overview
Handles whether or not the path, given by Rack::Request, matches any of the routes defined within the application.
Class Method Summary collapse
-
.params ⇒ Object
Stores parameters created when variable_route? finds a match.
-
.routes ⇒ Object
Stores all of the routes for the application.
-
.search(http, url) ⇒ Object
Searches url against defined routes.
-
.set_route(http_method, route, block) ⇒ Object
Adds a route to the routes array.
Class Method Details
.params ⇒ Object
Stores parameters created when variable_route? finds a match.
28 29 30 |
# File 'lib/cubic/router.rb', line 28 def params @param ||= {} end |
.routes ⇒ Object
Stores all of the routes for the application.
10 11 12 |
# File 'lib/cubic/router.rb', line 10 def routes @route ||= [] end |
.search(http, url) ⇒ Object
Searches url against defined routes. If none are found, we check if the url fits the pattern of a route containing variables.
21 22 23 24 25 |
# File 'lib/cubic/router.rb', line 21 def search(http, url) url = root_path?(url) route = routes.find { |i| i[:http_method] == http && i[:route] == url } route ? route : check_variable_routes(url, http) end |
.set_route(http_method, route, block) ⇒ Object
Adds a route to the routes array.
15 16 17 |
# File 'lib/cubic/router.rb', line 15 def set_route(http_method, route, block) routes << { http_method: http_method, route: route, block: block } end |