Class: Rosendo::Routes::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/rosendo/routes.rb

Defined Under Namespace

Classes: Path

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, &block) ⇒ Route

Returns a new instance of Route.



21
22
23
24
25
# File 'lib/rosendo/routes.rb', line 21

def initialize(method, path, &block)
  @method = method
  @path = Path.new(path)
  @block = block
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



20
21
22
# File 'lib/rosendo/routes.rb', line 20

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/rosendo/routes.rb', line 20

def path
  @path
end

Instance Method Details

#call(request, response) ⇒ Object



32
33
34
# File 'lib/rosendo/routes.rb', line 32

def call(request, response)
  DSL.new(request, response, path.params(request.url)).instance_eval(&@block)
end

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/rosendo/routes.rb', line 27

def matches?(request)
  method == request.method &&
  path.matches?(request.url)
end