Sha256: 89217bc7de6eba14bbcfd995cd5127826c4c253bdaa14ffced0194bf79ddaf86
Contents?: true
Size: 745 Bytes
Versions: 6
Compression:
Stored size: 745 Bytes
Contents
# frozen_string_literal: true require 'diff/lcs' require "modern/app/router" require 'modern/util/trie_node' module Modern class App class TrieRouter < Router def initialize(inputs) super(inputs) @trie = build_trie(routes) end def resolve(http_method, path) trie_path = path.sub(%r|^/|, "").split("/") + [http_method.to_s.upcase] @trie.get(trie_path) end private def build_trie(routes) trie = Modern::Util::TrieNode.new routes.each do |route| route.path_matcher # pre-seed the path matcher trie.add(route.route_tokens + [route.http_method], route, raise_if_present: true) end trie end end end end
Version data entries
6 entries across 6 versions & 1 rubygems