Class: Modern::App::TrieRouter

Inherits:
Router
  • Object
show all
Defined in:
lib/modern/app/trie_router.rb

Instance Method Summary collapse

Constructor Details

#initialize(inputs) ⇒ TrieRouter

Returns a new instance of TrieRouter.



12
13
14
15
16
# File 'lib/modern/app/trie_router.rb', line 12

def initialize(inputs)
  super(inputs)

  @trie = build_trie(routes)
end

Instance Method Details

#resolve(http_method, path) ⇒ Object



18
19
20
21
# File 'lib/modern/app/trie_router.rb', line 18

def resolve(http_method, path)
  trie_path = path.sub(%r|^/|, "").split("/") + [http_method.to_s.upcase]
  @trie.get(trie_path)
end