rack-rscript 0.1.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/rack_rscript.rb +28 -0
  2. metadata +11 -33
  3. data/lib/rack-rscript.rb +0 -86
@@ -0,0 +1,28 @@
1
+ require 'rcscript'
2
+
3
+ class RackRscript
4
+
5
+ def initialize(url='http://rorbuilder.info/r/heroku-rack/')
6
+ @@version = '0.3.1'
7
+ @url_base = url
8
+ end
9
+
10
+ def run_rcscript(rsf_url, jobs, arg='')
11
+ args = [jobs.map {|x| "//job:" + x}.join("\n"), rsf_url]
12
+ rs = RScript.new()
13
+ rs.run(args)
14
+ end
15
+
16
+ def call(env)
17
+ req = Rack::Request.new(env)
18
+ package_id, *jobs = req.params['package'], req.params['job']
19
+ *args = req.params['arg']
20
+
21
+ url = "%s%s.rsf" % [@url_base, package_id]
22
+ @content_type = "text/html"
23
+
24
+ code = run_rcscript(url, jobs, args).first
25
+ content = eval(code)
26
+ [200, {"Content-Type" => @content_type}, [content]]
27
+ end
28
+ end
metadata CHANGED
@@ -1,40 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-rscript
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.1
4
+ version: 0.3.1
6
5
  platform: ruby
7
- authors:
8
- - James Robertson
6
+ authors: []
7
+
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2012-02-26 00:00:00 +00:00
12
+ date: 2010-01-15 00:00:00 +00:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: app-routes
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
25
- type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rscript
29
- prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
36
- type: :runtime
37
- version_requirements: *id002
14
+ dependencies: []
15
+
38
16
  description:
39
17
  email:
40
18
  executables: []
@@ -44,7 +22,7 @@ extensions: []
44
22
  extra_rdoc_files: []
45
23
 
46
24
  files:
47
- - lib/rack-rscript.rb
25
+ - lib/rack_rscript.rb
48
26
  has_rdoc: true
49
27
  homepage:
50
28
  licenses: []
@@ -55,23 +33,23 @@ rdoc_options: []
55
33
  require_paths:
56
34
  - lib
57
35
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
36
  requirements:
60
37
  - - ">="
61
38
  - !ruby/object:Gem::Version
62
39
  version: "0"
40
+ version:
63
41
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
42
  requirements:
66
43
  - - ">="
67
44
  - !ruby/object:Gem::Version
68
45
  version: "0"
46
+ version:
69
47
  requirements: []
70
48
 
71
49
  rubyforge_project:
72
- rubygems_version: 1.5.2
50
+ rubygems_version: 1.3.5
73
51
  signing_key:
74
52
  specification_version: 3
75
- summary: Rack-Rscript is a light-weight alternative to Sinatra-Rscript.
53
+ summary: rack-rscript
76
54
  test_files: []
77
55
 
data/lib/rack-rscript.rb DELETED
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # file: rack-rscript.rb
4
-
5
-
6
- require 'rscript'
7
- require 'app-routes'
8
-
9
- class RackRscript
10
- include AppRoutes
11
-
12
- def initialize(raw_opts={})
13
-
14
- opts = {logfile: '', logrotate: 'daily', pkg_src: ''}.merge(raw_opts)
15
- @url_base = opts[:pkg_src] # web server serving the RSF files
16
- @url_base += '/' unless @url_base[-1] == '/'
17
- @log = false
18
-
19
- if opts[:logfile].length > 0 then
20
- @log = true
21
- @logger = Logger.new(opts[:logfile], opts[:logrotate])
22
- end
23
-
24
- super() # required for app-routes initialize method to exectue
25
- default_routes(@params)
26
- end
27
-
28
- def call(env)
29
- request = env['REQUEST_URI'][/https?:\/\/[^\/]+(.*)/,1]
30
-
31
- log Time.now.to_s + ": " + request
32
- content, content_type, status_code = run_route(request)
33
- content, status_code = "404: page not found", 404 if content.nil?
34
-
35
- content_type ||= 'text/html'
36
- status_code ||= 200
37
- [status_code, {"Content-Type" => content_type}, [content]]
38
- end
39
-
40
- private
41
-
42
- def default_routes(params)
43
-
44
- get '/do/:package/:job' do |package,job|
45
- run_job("%s%s.rsf" % [@url_base, package], "//job:" + job, params)
46
- end
47
-
48
- get '/do/:package/:job/*' do |package, job|
49
- raw_args = params[:splat]
50
- args = raw_args.join.split('/')[1..-1]
51
- run_job("%s%s.rsf" % [@url_base, package], "//job:" + job, params, args)
52
- end
53
- end
54
-
55
- def run_job(url, jobs, params={}, *qargs)
56
- if params[:splat] and params[:splat].length > 0 then
57
- h = params[:splat].first[1..-1].split('&').inject({}) do |r,x|
58
- k, v = x.split('=')
59
- r.merge(k.to_sym => v)
60
- end
61
- params.merge! h
62
- end
63
-
64
- result, args = RScript.new.read([url, jobs.split(/\s/), \
65
- qargs].flatten)
66
- rws = self
67
-
68
- begin
69
- r = eval result
70
- @params = {}
71
- return r
72
-
73
- rescue Exception => e
74
-
75
- err_label = e.message.to_s + " :: \n" + e.backtrace.join("\n")
76
- log(err_label)
77
- ($!).to_s
78
- end
79
- end
80
-
81
- def log(msg)
82
- if @log == true then
83
- @logger.debug msg
84
- end
85
- end
86
- end