class Sorta::Http::Web::Router
Public Class Methods
build_from(template)
click to toggle source
# File lib/sorta/http/web/router.rb, line 7 def self.build_from(template) router = new template.routes.each do |route| router.send(route[0], route[1], to: route[2], schema: route[3]) end router end
new()
click to toggle source
# File lib/sorta/http/web/router.rb, line 15 def initialize @tree = Radix::Tree.new end
Public Instance Methods
find(env)
click to toggle source
# File lib/sorta/http/web/router.rb, line 19 def find(env) key = File.join(env['PATH_INFO'], env['REQUEST_METHOD'].downcase) @tree.find key end
Private Instance Methods
add_route(path, method:, to:, schema:)
click to toggle source
# File lib/sorta/http/web/router.rb, line 34 def add_route(path, method:, to:, schema:) raise 'routing error' if to.nil? key = File.join(path, method.to_s.downcase) @tree.add key, { action: to, schema: schema } true end