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.
58 59 60 |
# File 'lib/hanami/middleware/trie.rb', line 58 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 52 53 54 |
# File 'lib/hanami/middleware/trie.rb', line 39 def find(path) node = @root app = @root.app # Track the deepest scope with an app on the way down. When the descent stops early (a # segment with no matching child under a node that has children), the request is still # within that scope, so its middleware must apply. for_each_segment(path) do |segment| node = node.get(segment) break unless node app = node.app if node.app? end 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 |