Class: Hanami::Middleware::Node Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/middleware/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 to register scopes with custom Rack middleware

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/middleware/node.rb', line 18

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

Instance Attribute Details

#appObject (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/middleware/node.rb', line 14

def app
  @app
end

Instance Method Details

#app!(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



64
65
66
# File 'lib/hanami/middleware/node.rb', line 64

def app!(app)
  @app = app
end

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



70
71
72
# File 'lib/hanami/middleware/node.rb', line 70

def app?
  !@app.nil?
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



26
27
28
29
30
# File 'lib/hanami/middleware/node.rb', line 26

def freeze
  @variable.freeze
  @fixed.freeze
  super
end

#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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/hanami/middleware/node.rb', line 46

def get(segment) # rubocop:disable Metrics/PerceivedComplexity
  found = @fixed&.fetch(segment, nil)
  return found if found

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

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

  return found if found

  self if leaf?
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



76
77
78
# File 'lib/hanami/middleware/node.rb', line 76

def leaf?
  @fixed.nil? && @variable.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



34
35
36
37
38
39
40
41
42
# File 'lib/hanami/middleware/node.rb', line 34

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

#segment_for(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.3



88
89
90
# File 'lib/hanami/middleware/node.rb', line 88

def segment_for(segment)
  Router::Segment.fabricate(segment)
end

#variable?(segment) ⇒ 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.3



82
83
84
# File 'lib/hanami/middleware/node.rb', line 82

def variable?(segment)
  Router::ROUTE_VARIABLE_MATCHER.match?(segment)
end