app-routes 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/app-routes.rb +8 -2
- metadata +1 -1
data/lib/app-routes.rb
CHANGED
@@ -19,16 +19,20 @@ class AppRoutes
|
|
19
19
|
result = nil
|
20
20
|
|
21
21
|
@route.each do |key, block|
|
22
|
+
p 'key : ' + key.inspect
|
22
23
|
match = request.match(key)
|
23
24
|
|
24
25
|
if match then
|
25
26
|
|
26
27
|
args = match.captures
|
28
|
+
p args
|
27
29
|
@params[:captures] = *args
|
28
30
|
|
29
31
|
if @route[key][:s] then
|
30
32
|
raw_params = @route[key][:s].gsub(':','').match(key).captures
|
31
|
-
|
33
|
+
splat, raw_params2 = raw_params.each_with_index.partition {|x,i| x == '/*'}
|
34
|
+
@params[:splat] = splat.map {|x,i| v = args[i]; args.delete_at(i); v}
|
35
|
+
@params.merge!(Hash[raw_params2.map{|x,i| x.to_sym}.zip(args)])
|
32
36
|
end
|
33
37
|
|
34
38
|
result = @route[key][:block].call *args
|
@@ -45,8 +49,10 @@ class AppRoutes
|
|
45
49
|
send (methodx[arg.class.to_s.to_sym]), arg, &block
|
46
50
|
end
|
47
51
|
|
52
|
+
private
|
53
|
+
|
48
54
|
def string_get(raw_s, &block)
|
49
|
-
s = raw_s.gsub(/\:\w+/,'(\w+)')
|
55
|
+
s = raw_s.gsub(/\:\w+/,'(\w+)').gsub(/\/\*/,'(.*)')
|
50
56
|
@route[Regexp.new s] = {s: raw_s, block: block}
|
51
57
|
end
|
52
58
|
|