rack-rscript 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rack-rscript.rb +43 -18
- metadata +2 -2
data/lib/rack-rscript.rb
CHANGED
|
@@ -8,20 +8,29 @@ require 'app-routes'
|
|
|
8
8
|
require 'requestor'
|
|
9
9
|
require 'logger'
|
|
10
10
|
|
|
11
|
+
class Redirect
|
|
12
|
+
attr_reader :to_url
|
|
13
|
+
|
|
14
|
+
def initialize(url)
|
|
15
|
+
@to_url = url
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
11
19
|
class RackRscript
|
|
12
20
|
include AppRoutes
|
|
13
21
|
|
|
14
22
|
def initialize(raw_opts={})
|
|
15
23
|
@params = {}
|
|
16
|
-
|
|
24
|
+
|
|
17
25
|
opts = {logfile: '', logrotate: 'daily', pkg_src: ''}.merge(raw_opts)
|
|
18
26
|
@url_base = opts[:pkg_src] # web server serving the RSF files
|
|
19
27
|
@url_base += '/' unless @url_base[-1] == '/'
|
|
28
|
+
|
|
20
29
|
@log = false
|
|
21
30
|
|
|
22
31
|
if opts[:logfile].length > 0 then
|
|
23
32
|
@log = true
|
|
24
|
-
@logger = Logger.new(opts[:logfile], opts[:logrotate])
|
|
33
|
+
@logger = Logger.new(opts[:logfile], opts[:logrotate])
|
|
25
34
|
end
|
|
26
35
|
|
|
27
36
|
super() # required for app-routes initialize method to exectue
|
|
@@ -29,24 +38,36 @@ class RackRscript
|
|
|
29
38
|
end
|
|
30
39
|
|
|
31
40
|
def call(env)
|
|
41
|
+
@env = env
|
|
32
42
|
request = env['REQUEST_URI'][/https?:\/\/[^\/]+(.*)/,1]
|
|
33
43
|
|
|
34
|
-
log
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
log "_: " + env.keys.inspect
|
|
45
|
+
log Time.now.to_s + "_: " + env.inspect
|
|
46
|
+
content, content_type, status_code = run_route(request)
|
|
47
|
+
|
|
48
|
+
if content.is_a? Redirect then
|
|
49
|
+
redirectx = content
|
|
50
|
+
res = Rack::Response.new
|
|
51
|
+
res.redirect(redirectx.to_url)
|
|
52
|
+
res.finish
|
|
53
|
+
else
|
|
54
|
+
|
|
55
|
+
if content.nil? then
|
|
56
|
+
e = $!
|
|
57
|
+
log(e) if e
|
|
58
|
+
content, status_code = "404: page not found", 404
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
content_type ||= 'text/html'
|
|
62
|
+
status_code ||= 200
|
|
63
|
+
|
|
64
|
+
[status_code, {"Content-Type" => content_type}, [content]]
|
|
40
65
|
end
|
|
41
|
-
|
|
42
|
-
content_type ||= 'text/html'
|
|
43
|
-
status_code ||= 200
|
|
44
|
-
[status_code, {"Content-Type" => content_type}, [content]]
|
|
45
66
|
end
|
|
46
67
|
|
|
47
68
|
|
|
48
69
|
def run_job(url, jobs, params={}, *qargs)
|
|
49
|
-
|
|
70
|
+
|
|
50
71
|
if @params[:splat] then
|
|
51
72
|
@params.each do |k,v|
|
|
52
73
|
@params.delete k unless k == :splat or k == :package or k == :job or k == :captures
|
|
@@ -59,8 +80,8 @@ class RackRscript
|
|
|
59
80
|
v ? r.merge(k[/\w+$/].to_sym => v) : r
|
|
60
81
|
end
|
|
61
82
|
@params.merge! h
|
|
62
|
-
end
|
|
63
|
-
|
|
83
|
+
end
|
|
84
|
+
|
|
64
85
|
result, args = RScript.new.read([url, jobs.split(/\s/), \
|
|
65
86
|
qargs].flatten)
|
|
66
87
|
rws = self
|
|
@@ -83,6 +104,10 @@ class RackRscript
|
|
|
83
104
|
end
|
|
84
105
|
end
|
|
85
106
|
|
|
107
|
+
def redirect(url)
|
|
108
|
+
Redirect.new url
|
|
109
|
+
end
|
|
110
|
+
|
|
86
111
|
private
|
|
87
112
|
|
|
88
113
|
def default_routes(params)
|
|
@@ -95,8 +120,8 @@ class RackRscript
|
|
|
95
120
|
raw_args = params[:splat]
|
|
96
121
|
args = raw_args.first[1..-1][/.[\/\w]+/].split('/')
|
|
97
122
|
run_job("%s%s.rsf" % [@url_base, package], "//job:" + job, params, args)
|
|
98
|
-
end
|
|
123
|
+
end
|
|
124
|
+
|
|
99
125
|
end
|
|
100
|
-
|
|
101
|
-
|
|
126
|
+
|
|
102
127
|
end
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: rack-rscript
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.4.
|
|
5
|
+
version: 0.4.7
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- James Robertson
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2012-
|
|
13
|
+
date: 2012-10-15 00:00:00 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rack
|