Class: Hanami::Router::Node Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/router/node.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 node

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Node

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 Node.

Since:

  • 2.0.0



18
19
20
21
22
# File 'lib/hanami/router/node.rb', line 18

def initialize
  @variable = nil
  @fixed = nil
  @leaves = nil
end

Instance Attribute Details

#to ⇒ Object (readonly)

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



14
15
16
# File 'lib/hanami/router/node.rb', line 14

def to
  @to
end

Instance Method Details

#get(segment) ⇒ 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



37
38
39
# File 'lib/hanami/router/node.rb', line 37

def get(segment)
  @fixed&.fetch(segment, nil) || @variable
end

#leaf!(route, to, constraints) ⇒ 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



43
44
45
46
# File 'lib/hanami/router/node.rb', line 43

def leaf!(route, to, constraints)
  @leaves ||= []
  @leaves << Leaf.new(route, to, constraints)
end

#match(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.

Returns the endpoint and captured params of the first leaf matching the given path, or nil.

Since:

  • 2.2.0



52
53
54
55
56
57
58
59
# File 'lib/hanami/router/node.rb', line 52

def match(path)
  @leaves&.each do |leaf|
    params = leaf.match(path)
    return [leaf.to, params] if params
  end

  nil
end

#put(segment) ⇒ 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



26
27
28
29
30
31
32
33
# File 'lib/hanami/router/node.rb', line 26

def put(segment)
  if variable?(segment)
    @variable ||= self.class.new
  else
    @fixed ||= {}
    @fixed[segment] ||= self.class.new
  end
end