Class: Truss::Router::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/truss/router/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
    @request_method, @path, @endpoint = method, path, endpoint
    @has_dynamic_segments = false
    @matchable_regex = build_matchable_regex(method, path, options)
    @allowed_methods = discover_allowed_methods(method, path, options)
    @path_segments   = get_path_segments(path)
    @options = options
end

Instance Attribute Details

#allowed_methodsObject

Returns the value of attribute allowed_methods.



4
5
6
# File 'lib/truss/router/node.rb', line 4

def allowed_methods
  @allowed_methods
end

#endpointObject

Returns the value of attribute endpoint.



4
5
6
# File 'lib/truss/router/node.rb', line 4

def endpoint
  @endpoint
end

#has_dynamic_segmentsObject

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_regexObject

Returns the value of attribute matchable_regex.



4
5
6
# File 'lib/truss/router/node.rb', line 4

def matchable_regex
  @matchable_regex
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/truss/router/node.rb', line 4

def options
  @options
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/truss/router/node.rb', line 4

def path
  @path
end

#path_segmentsObject

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_methodObject

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

Returns:

  • (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