10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/dandy/routing/matcher.rb', line 10
def match(path, http_method)
segments = path.split('/').concat(['/'])
params = {}
matched = nil
@routes.each do |route|
if route.segments.length == segments.length
for i in 0..segments.length - 1 do
template = route.segments[i]
value = segments[i]
if value == template
elsif template.index('$') == 0
name = template.sub('$', '')
params[name] = value
else
break
end
if i == segments.length - 1 && route.http_verb == http_method
matched = route
end
end
end
end
matched.nil? ? nil : Match.new(matched, params)
end
|