Class: SRScript
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- SRScript
- Defined in:
- lib/srscript.rb
Constant Summary collapse
- URL_BASE =
'http://rorbuilder.info/r/heroku/'- @@count =
0- @@rscript =
RScript.new()
- @@url_base =
'http://rorbuilder.info/r/heroku/'- @@get_routes =
{}
- @@post_routes =
{}
- @@services =
{}
- @@templates =
{}
- @@app =
nil
Instance Method Summary collapse
- #check_url(url) ⇒ Object
- #display_url_run(url, jobs, opts) ⇒ Object
- #follow_route(routes, key) ⇒ Object
-
#initialize ⇒ SRScript
constructor
A new instance of SRScript.
- #package_run(package_id, job, opts = {}) ⇒ Object
- #run_rcscript(rsf_url, jobs, raw_args = []) ⇒ Object
- #run_script(url, jobs, *qargs) ⇒ Object
Constructor Details
#initialize ⇒ SRScript
Returns a new instance of SRScript.
25 26 27 28 |
# File 'lib/srscript.rb', line 25 def initialize() super puts 'initialized at ' + Time.now.to_s end |
Instance Method Details
#check_url(url) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/srscript.rb', line 71 def check_url(url) url = URI.parse(url) Net::HTTP.start(url.host, url.port) do |http| return http.head(url.request_uri).code end end |
#display_url_run(url, jobs, opts) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/srscript.rb', line 62 def display_url_run(url, jobs, opts) h = {'.xml' => 'text/xml','.html' => 'text/html','.txt' => 'text/plain'} @content_type = h[opts[:extension]] out = run_script(url, jobs, opts[:args]) content_type @content_type, :charset => 'utf-8' if defined? content_type out end |
#follow_route(routes, key) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/srscript.rb', line 291 def follow_route(routes, key) if routes.has_key? key then routes[key].call(params) else route = routes.detect {|k,v| key[/#{k}/]} if route then remaining = $' if remaining then args = remaining.split('/') args.shift else args = [] end route[1].call( params, args) else puts '@@app is ' + @@app.inspect out, @content_type = @@app.run_projectx('dir', 'view', {:file_path => key, :passthru => params[:passthru]}) [out, @content_type] #puts "no match" end end end |
#package_run(package_id, job, opts = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/srscript.rb', line 78 def package_run(package_id, job, opts={}) o = { :extension => '.html', :args => [] }.merge(opts) jobs = "//job:" + job url, @content_type = @@app.run_projectx('registry', 'get-key', :path => "system/packages/*[name='#{package_id}']/url/text()").map(&:to_s) url = @@url_base + url[1..-1] if url[/^\//] if url then display_url_run(url.to_s.sub(/^#{@@url_base}/,'\0s/open/'),jobs, o) else code = check_url(url) if code == '200' then url = "%s%s.rsf" % [@@url_base, package_id] display_url_run(url,jobs, o) else # 404 url = url_base + 'open-uri-error.rsf' run_script(url, '//job:with-code', code) end end end |
#run_rcscript(rsf_url, jobs, raw_args = []) ⇒ Object
53 54 55 |
# File 'lib/srscript.rb', line 53 def run_rcscript(rsf_url, jobs, raw_args=[]) @@rscript.read([rsf_url, jobs.split(/\s/), raw_args].flatten) end |
#run_script(url, jobs, *qargs) ⇒ Object
57 58 59 60 |
# File 'lib/srscript.rb', line 57 def run_script(url, jobs, *qargs) result, args = run_rcscript(url, jobs, qargs) eval(result) end |