Class: Galago::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/galago/router/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Route

Returns a new instance of Route.



7
8
9
10
# File 'lib/galago/router/route.rb', line 7

def initialize(path)
  @path = Router::Path.new(path)
  @endpoints = { 'OPTIONS' => options }
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/galago/router/route.rb', line 5

def path
  @path
end

Instance Method Details

#add_endpoint(request_method, endpoint) ⇒ Object



12
13
14
# File 'lib/galago/router/route.rb', line 12

def add_endpoint(request_method, endpoint)
  @endpoints[request_method] = endpoint
end

#allowed_methodsObject



16
17
18
# File 'lib/galago/router/route.rb', line 16

def allowed_methods
  @endpoints.keys.sort
end

#call(env) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/galago/router/route.rb', line 24

def call(env)
  env['galago_router.path'] = @path.to_s
  env['galago_router.params'] = @path.params_from(env)

  endpoint = @endpoints.fetch(env['REQUEST_METHOD'], method_not_allowed)
  endpoint.call(env)
end

#recognizes_path?(request_path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/galago/router/route.rb', line 20

def recognizes_path?(request_path)
  @path.recognizes?(request_path)
end