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.



5
6
7
8
9
# File 'lib/truss/router/node.rb', line 5

def initialize(method, path, endpoint, options={})
    @request_method, @path, @endpoint = method, path, endpoint
    @matchable_regex = build_matchable_regex(method, path, options)
    @options = options
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
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

#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



15
16
17
# File 'lib/truss/router/node.rb', line 15

def call request
    endpoint.call(request)
end

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/truss/router/node.rb', line 11

def matches? request
    matchable_regex.match(request.routing_path)
end