Class: Hanami::API::Middleware::Trie Private

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

Since:

  • 0.1.1

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:

  • 0.1.1



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.

Since:

  • 0.1.1



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.

Returns:

  • (Boolean)

Since:

  • 0.1.1



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.

Since:

  • 0.1.1



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

#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:

  • 0.1.1



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

def freeze
  @root.freeze
  super
end