Class: Hanami::Router::Trie Private
- Inherits:
-
Object
- Object
- Hanami::Router::Trie
- Defined in:
- lib/hanami/router/trie.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Trie data structure to store routes
Instance Attribute Summary collapse
- #root ⇒ Object readonly private
Instance Method Summary collapse
- #add(route, to, constraints) ⇒ Object private
- #find(path) ⇒ Object private
-
#initialize ⇒ Trie
constructor
private
A new instance of Trie.
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/hanami/router/trie.rb', line 14 def root @root end |
Instance Method Details
#add(route, to, constraints) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hanami/router/trie.rb', line 24 def add(route, to, constraints) segments = segments_from(route) node = @root segments.each do |segment| node = node.put(segment) end node.leaf!(route, to, constraints) end |
#find(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 |
# File 'lib/hanami/router/trie.rb', line 37 def find(path) segments = segments_from(path) node = @root return unless segments.all? { |segment| node = node.get(segment) } node.match(path)&.then { |found| [found.to, found.params] } end |