Class: Hanami::Middleware::Trie Private

Inherits:
Object
  • Object
show all
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

Since:

  • 2.0.0

Instance Method Summary collapse

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.

Since:

  • 2.0.0



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.

Since:

  • 2.0.0



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.

Returns:

  • (Boolean)

Since:

  • 2.0.0



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.

Since:

  • 2.0.0



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

#freezeObject

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.

Since:

  • 2.0.0



21
22
23
24
# File 'lib/hanami/middleware/trie.rb', line 21

def freeze
  @root.freeze
  super
end