Class: Hanami::Middleware::Trie Private
- Inherits:
-
Object
- Object
- Hanami::Middleware::Trie
- Defined in:
- lib/hanami/middleware/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 to register scopes with custom Rack middleware
Instance Method Summary collapse
- #add(path, app) ⇒ Object private
- #empty? ⇒ Boolean private
- #find(path) ⇒ Object private
- #freeze ⇒ Object private
-
#initialize(app) ⇒ Trie
constructor
private
A new instance of Trie.
Constructor Details
#initialize(app) ⇒ 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.
14 15 16 17 |
# File 'lib/hanami/middleware/trie.rb', line 14 def initialize(app) @app = app @root = Node.new end |
Instance Method Details
#add(path, app) ⇒ 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.
28 29 30 31 32 33 34 35 |
# File 'lib/hanami/middleware/trie.rb', line 28 def add(path, app) node = @root for_each_segment(path) do |segment| node = node.put(segment) end node.app!(app) end |
#empty? ⇒ Boolean
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.
55 56 57 |
# File 'lib/hanami/middleware/trie.rb', line 55 def empty? @root.leaf? 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.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hanami/middleware/trie.rb', line 39 def find(path) node = @root for_each_segment(path) do |segment| break unless node node = node.get(segment) end return node.app if node&.app? @root.app || @app end |
#freeze ⇒ 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.
21 22 23 24 |
# File 'lib/hanami/middleware/trie.rb', line 21 def freeze @root.freeze super end |