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

#initializeNode

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
  @to = nil
end

Instance Attribute Details

#toObject (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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hanami/router/node.rb', line 39

def get(segment) # rubocop:disable Metrics/PerceivedComplexity
  return unless @variable || @fixed

  found = nil
  captured = nil

  found = @fixed&.fetch(segment, nil)
  return [found, nil] if found

  @variable&.each do |matcher, node|
    break if found

    captured = matcher.match(segment)
    found = node if captured
  end

  [found, captured&.named_captures]
end

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



66
67
68
# File 'lib/hanami/router/node.rb', line 66

def leaf!(to)
  @to = to
end

#leaf?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



60
61
62
# File 'lib/hanami/router/node.rb', line 60

def leaf?
  @to
end

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



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

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