Class: Hanami::Middleware::Node Private
- Inherits:
-
Object
- Object
- Hanami::Middleware::Node
- 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
Instance Attribute Summary collapse
- #app ⇒ Object readonly private
Instance Method Summary collapse
- #app!(app) ⇒ Object private
- #app? ⇒ Boolean private
- #freeze ⇒ Object private
- #get(segment) ⇒ Object private
-
#initialize ⇒ Node
constructor
private
A new instance of Node.
- #leaf? ⇒ Boolean private
- #put(segment) ⇒ Object private
- #segment_for(segment) ⇒ Object private
- #variable?(segment) ⇒ Boolean 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/middleware/node.rb', line 18 def initialize @app = nil @variable = nil @fixed = nil end |
Instance Attribute Details
#app ⇒ 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/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.
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.
70 71 72 |
# File 'lib/hanami/middleware/node.rb', line 70 def app? !@app.nil? end |
#freeze ⇒ 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 |
# 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.
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.
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.
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.
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.
82 83 84 |
# File 'lib/hanami/middleware/node.rb', line 82 def variable?(segment) Router::ROUTE_VARIABLE_MATCHER.match?(segment) end |