Class: Cubic::Router

Inherits:
Object
  • Object
show all
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

Class Method Details

.paramsObject

Stores parameters created when variable_route? finds a match.



28
29
30
# File 'lib/cubic/router.rb', line 28

def params
  @param ||= {}
end

.routesObject

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