Class: Hanami::API::Middleware::Trie Private
- Inherits:
-
Object
- Object
- Hanami::API::Middleware::Trie
- Defined in:
- lib/hanami/api/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.
15 16 17 18 |
# File 'lib/hanami/api/middleware/trie.rb', line 15 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.
29 30 31 32 33 34 35 36 |
# File 'lib/hanami/api/middleware/trie.rb', line 29 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.
56 57 58 |
# File 'lib/hanami/api/middleware/trie.rb', line 56 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.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hanami/api/middleware/trie.rb', line 40 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.
22 23 24 25 |
# File 'lib/hanami/api/middleware/trie.rb', line 22 def freeze @root.freeze super end |