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
#initialize ⇒ Trie
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.
Returns a new instance of Trie.
18 19 20 21 |
# File 'lib/hanami/router/trie.rb', line 18 def initialize @root = Node.new @segments_map = {} end |
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.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hanami/router/trie.rb', line 25 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.
38 39 40 41 42 43 44 45 |
# File 'lib/hanami/router/trie.rb', line 38 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 |