Class: SimpleRouter::Routes

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

Defined Under Namespace

Classes: Route

Instance Method Summary collapse

Instance Method Details

#add(*args, &action) ⇒ Object



4
5
6
# File 'lib/simple_router/routes.rb', line 4

def add(*args, &action)
  self << Route.new(*args, &action)
end

#match(verb, path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simple_router/routes.rb', line 8

def match(verb, path)
  return nil if self.empty?

  verb = verb.to_s.downcase.strip.to_sym

  routes = self.select {|route| route.verb == verb }
  paths  = routes.map  {|route| route.path }

  path, values = SimpleRouter.engine.match(path, paths)
  return nil if path.nil?

  route = routes.detect {|route| route.path == path }
  route.values = values
  route
end