Class: Hanami::Router::Node Private
- Inherits:
-
Object
- Object
- Hanami::Router::Node
- 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
Instance Attribute Summary collapse
- #to ⇒ Object readonly private
Instance Method Summary collapse
- #get(segment) ⇒ Object private
-
#initialize ⇒ Node
constructor
private
A new instance of Node.
- #leaf!(to) ⇒ Object private
- #leaf? ⇒ Boolean private
- #put(segment, constraints) ⇒ Object private
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.
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
#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.
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.
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.
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.
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.
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 |