class Jeanine::Router
Attributes
routes[R]
Public Class Methods
new()
click to toggle source
# File lib/jeanine/router.rb, line 10 def initialize @routes = { GET: [], POST: [], PATCH: [], PUT: [], DELETE: [], OPTIONS: [], HEAD: [], } end
Public Instance Methods
add(verb, path, options = {}, &block)
click to toggle source
# File lib/jeanine/router.rb, line 22 def add(verb, path, options = {}, &block) routes[verb] << build_route("#{path}", options, &block) end
Private Instance Methods
build_route(path, options = {}, &block)
click to toggle source
# File lib/jeanine/router.rb, line 28 def build_route(path, options = {}, &block) route = { path: "#{path}", compiled_path: nil, params: [], block: block } compiled_path = route[:path].gsub(/:\w+/) do |match| route[:params] << match.tr(':', '').to_sym '([^/?#]+)' end route[:compiled_path] = /^#{compiled_path}?$/ route end