Class: Truss::Router::Node
- Inherits:
-
Object
- Object
- Truss::Router::Node
- Defined in:
- lib/truss/router/node.rb
Direct Known Subclasses
Routes::Delete, Routes::Get, Routes::Head, Routes::Options, Routes::Patch, Routes::Post, Routes::Put
Instance Attribute Summary collapse
-
#allowed_methods ⇒ Object
Returns the value of attribute allowed_methods.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#has_dynamic_segments ⇒ Object
Returns the value of attribute has_dynamic_segments.
-
#matchable_regex ⇒ Object
Returns the value of attribute matchable_regex.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#path_segments ⇒ Object
Returns the value of attribute path_segments.
-
#request_method ⇒ Object
Returns the value of attribute request_method.
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(method, path, endpoint, options = {}) ⇒ Node
constructor
A new instance of Node.
- #matches?(request) ⇒ Boolean
Constructor Details
#initialize(method, path, endpoint, options = {}) ⇒ Node
Returns a new instance of Node.
8 9 10 11 12 13 14 15 |
# File 'lib/truss/router/node.rb', line 8 def initialize(method, path, endpoint, ={}) @request_method, @path, @endpoint = method, path, endpoint @has_dynamic_segments = false @matchable_regex = build_matchable_regex(method, path, ) @allowed_methods = discover_allowed_methods(method, path, ) @path_segments = get_path_segments(path) @options = end |
Instance Attribute Details
#allowed_methods ⇒ Object
Returns the value of attribute allowed_methods.
4 5 6 |
# File 'lib/truss/router/node.rb', line 4 def allowed_methods @allowed_methods end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
4 5 6 |
# File 'lib/truss/router/node.rb', line 4 def endpoint @endpoint end |
#has_dynamic_segments ⇒ Object
Returns the value of attribute has_dynamic_segments.
4 5 6 |
# File 'lib/truss/router/node.rb', line 4 def has_dynamic_segments @has_dynamic_segments end |
#matchable_regex ⇒ Object
Returns the value of attribute matchable_regex.
4 5 6 |
# File 'lib/truss/router/node.rb', line 4 def matchable_regex @matchable_regex end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/truss/router/node.rb', line 4 def @options end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/truss/router/node.rb', line 4 def path @path end |
#path_segments ⇒ Object
Returns the value of attribute path_segments.
4 5 6 |
# File 'lib/truss/router/node.rb', line 4 def path_segments @path_segments end |
#request_method ⇒ Object
Returns the value of attribute request_method.
4 5 6 |
# File 'lib/truss/router/node.rb', line 4 def request_method @request_method end |
Instance Method Details
#call(request) ⇒ Object
29 30 31 |
# File 'lib/truss/router/node.rb', line 29 def call request endpoint.call(request) end |
#matches?(request) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/truss/router/node.rb', line 17 def matches? request if has_dynamic_segments match = matchable_regex.match(request.routing_path) if match request.routing_params = Hash[match.names.zip(match.captures)] end match else matchable_regex.match(request.routing_path) end end |