app-routes 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/app-routes.rb +17 -11
- metadata +3 -5
data/lib/app-routes.rb
CHANGED
@@ -2,18 +2,25 @@
|
|
2
2
|
|
3
3
|
# file: app-routes.rb
|
4
4
|
|
5
|
+
require 'logger'
|
6
|
+
|
5
7
|
module AppRoutes
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
attr_accessor :routes
|
10
|
+
|
11
|
+
def initialize(logfile='/tmp/app-routes.log')
|
12
|
+
@routes = {}
|
9
13
|
@params = {}
|
14
|
+
@logger = Logger.new(logfile,'daily')
|
10
15
|
end
|
11
16
|
|
12
17
|
def run_route(request)
|
13
18
|
|
14
19
|
result = nil
|
15
20
|
|
16
|
-
|
21
|
+
routes = @routes
|
22
|
+
return unless routes
|
23
|
+
route = routes.detect {|key, block| request.match(key) }
|
17
24
|
|
18
25
|
if route then
|
19
26
|
key, block = route
|
@@ -22,20 +29,20 @@ module AppRoutes
|
|
22
29
|
args = match.captures
|
23
30
|
@params[:captures] = *args
|
24
31
|
|
25
|
-
if
|
26
|
-
raw_params =
|
32
|
+
if routes[key][:s] then
|
33
|
+
raw_params = routes[key][:s].gsub(':','').match(key).captures
|
27
34
|
splat, raw_params2 = raw_params.each_with_index.partition {|x,i| x == '/*'}
|
28
35
|
@params[:splat] = splat.map {|x,i| v = args[i]; args.delete_at(i); v}
|
29
36
|
@params.merge!(Hash[raw_params2.map{|x,i| x.to_sym}.zip(args)])
|
30
37
|
end
|
31
38
|
|
32
39
|
begin
|
33
|
-
result =
|
40
|
+
result = routes[key][:block].call *args
|
34
41
|
rescue Exception => e
|
35
42
|
|
36
43
|
err_label = e.message + " :: \n" + e.backtrace.join("\n")
|
37
|
-
|
38
|
-
"app-routes error: " + ($!).to_s
|
44
|
+
@logger.debug err_label
|
45
|
+
@logger.debug "app-routes error: " + ($!).to_s
|
39
46
|
end
|
40
47
|
|
41
48
|
end
|
@@ -55,12 +62,11 @@ module AppRoutes
|
|
55
62
|
|
56
63
|
def string_get(raw_s, &block)
|
57
64
|
s = "^%s$" % raw_s.gsub(/\:[\w-]+/,'([\w-]+)').gsub(/\/\*/,'(.*)')
|
58
|
-
@
|
65
|
+
@routes[Regexp.new s] = {s: raw_s, block: block}
|
59
66
|
end
|
60
67
|
|
61
68
|
def regex_get(r, &block)
|
62
|
-
@
|
69
|
+
@routes[r] = {block: block}
|
63
70
|
end
|
64
71
|
|
65
72
|
end
|
66
|
-
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: app-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.12
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
14
|
-
default_executable:
|
13
|
+
date: 2012-05-27 00:00:00 Z
|
15
14
|
dependencies: []
|
16
15
|
|
17
16
|
description:
|
@@ -24,7 +23,6 @@ extra_rdoc_files: []
|
|
24
23
|
|
25
24
|
files:
|
26
25
|
- lib/app-routes.rb
|
27
|
-
has_rdoc: true
|
28
26
|
homepage:
|
29
27
|
licenses: []
|
30
28
|
|
@@ -48,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
46
|
requirements: []
|
49
47
|
|
50
48
|
rubyforge_project:
|
51
|
-
rubygems_version: 1.
|
49
|
+
rubygems_version: 1.8.23
|
52
50
|
signing_key:
|
53
51
|
specification_version: 3
|
54
52
|
summary: app-routes
|