module Blade::RackRouter
Constants
- DEFAULT
Public Instance Methods
default_route(action)
click to toggle source
# File lib/blade/rack/router.rb, line 19 def default_route(action) routes[DEFAULT] = { action: action } end
find_route(path)
click to toggle source
# File lib/blade/rack/router.rb, line 23 def find_route(path) if route = routes.detect { |key, details| path =~ details[:pattern] } route[1] else routes[DEFAULT] end end
route(path, action)
click to toggle source
# File lib/blade/rack/router.rb, line 11 def route(path, action) pattern = /^\/?#{path.gsub(/\*/, ".*")}$/ base_path = path.match(/([^\*]*)\*?/)[1] routes[path] = { action: action, pattern: pattern, base_path: base_path } self.routes = routes.sort_by { |path, value| -path.size }.to_h routes[path] end