Sha256: 1b1dd22cf39aaf55b0645e12c216dc99903f12d1006bc8a4d55b968f2f2d01ee
Contents?: true
Size: 813 Bytes
Versions: 19
Compression:
Stored size: 813 Bytes
Contents
require 'forwardable' module Jeanine class Router extend Forwardable def_delegators :@routes, :[] attr_reader :routes def initialize @routes = { GET: [], POST: [], PATCH: [], PUT: [], DELETE: [], OPTIONS: [], HEAD: [], } end def add(verb, path, options = {}, &block) routes[verb] << build_route("#{path}", options, &block) end private 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 end end
Version data entries
19 entries across 19 versions & 1 rubygems