Class: HttpRouter::Node
- Inherits:
-
Object
- Object
- HttpRouter::Node
- Defined in:
- lib/http_router/node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#catchall ⇒ Object
Returns the value of attribute catchall.
-
#extension_node ⇒ Object
readonly
Returns the value of attribute extension_node.
-
#linear ⇒ Object
readonly
Returns the value of attribute linear.
-
#lookup ⇒ Object
readonly
Returns the value of attribute lookup.
-
#request_node ⇒ Object
readonly
Returns the value of attribute request_node.
-
#value ⇒ Object
Returns the value of attribute value.
-
#variable ⇒ Object
Returns the value of attribute variable.
Instance Method Summary collapse
- #add(val) ⇒ Object
- #add_extension(ext) ⇒ Object
- #add_request_methods(options) ⇒ Object
-
#initialize(base) ⇒ Node
constructor
A new instance of Node.
- #reset! ⇒ Object
Constructor Details
#initialize(base) ⇒ Node
Returns a new instance of Node.
6 7 8 9 |
# File 'lib/http_router/node.rb', line 6 def initialize(base) @router = base reset! end |
Instance Attribute Details
#catchall ⇒ Object
Returns the value of attribute catchall.
3 4 5 |
# File 'lib/http_router/node.rb', line 3 def catchall @catchall end |
#extension_node ⇒ Object (readonly)
Returns the value of attribute extension_node.
4 5 6 |
# File 'lib/http_router/node.rb', line 4 def extension_node @extension_node end |
#linear ⇒ Object (readonly)
Returns the value of attribute linear.
4 5 6 |
# File 'lib/http_router/node.rb', line 4 def linear @linear end |
#lookup ⇒ Object (readonly)
Returns the value of attribute lookup.
4 5 6 |
# File 'lib/http_router/node.rb', line 4 def lookup @lookup end |
#request_node ⇒ Object (readonly)
Returns the value of attribute request_node.
4 5 6 |
# File 'lib/http_router/node.rb', line 4 def request_node @request_node end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/http_router/node.rb', line 3 def value @value end |
#variable ⇒ Object
Returns the value of attribute variable.
3 4 5 |
# File 'lib/http_router/node.rb', line 3 def variable @variable end |
Instance Method Details
#add(val) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/http_router/node.rb', line 17 def add(val) if val.is_a?(Variable) if val.matches_with new_node = router.node create_linear @linear << [val, new_node] new_node else @catchall ||= router.node @catchall.variable = val @catchall end elsif val.is_a?(Regexp) create_linear @linear << [val, router.node] @linear.last.last else create_lookup @lookup[val] ||= router.node end end |
#add_extension(ext) ⇒ Object
39 40 41 42 |
# File 'lib/http_router/node.rb', line 39 def add_extension(ext) @extension_node ||= router.node @extension_node.add(ext) end |
#add_request_methods(options) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/http_router/node.rb', line 44 def add_request_methods() if !.empty? generate_request_method_tree() elsif @request_node current_node = @request_node while current_node.request_method current_node = (current_node.catchall ||= router.request_node) end [current_node] else [self] end end |
#reset! ⇒ Object
11 12 13 14 15 |
# File 'lib/http_router/node.rb', line 11 def reset! @linear = nil @lookup = nil @catchall = nil end |