Public Instance methods
back()
Alias for referrer
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 260 def back 261 referrer 262 end
error(code=500, body = nil)
Halt processing and return the error status provided with the given code and optional body. If a single argument is given and it is not an integer, consider it the body and use a 500 status code.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 268 def error(code=500, body = nil) 269 unless code.is_a?(Integer) 270 body = code 271 code = 500 272 end 273 274 response.status = code 275 response.body = body if body 276 halt 277 end
not_found(body = nil)
Halt processing and return a 404 response with an optional body.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 280 def not_found(body = nil) 281 error(404, body) 282 end
redirect(path=(no_add_script_name = true; default_redirect_path), status=default_redirect_status)
If the absolute_redirects or :prefixed_redirects roda class options has been set, respect those and update the path.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 286 def redirect(path=(no_add_script_name = true; default_redirect_path), status=default_redirect_status) 287 opts = roda_class.opts 288 absolute_redirects = opts[:absolute_redirects] 289 prefixed_redirects = no_add_script_name ? false : opts[:prefixed_redirects] 290 path = uri(path, absolute_redirects, prefixed_redirects) if absolute_redirects || prefixed_redirects 291 super(path, status) 292 end
send_file(path, opts = OPTS)
Backwards compatibility for callers of r.send_file.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 295 def send_file(path, opts = OPTS) 296 scope.send_file(path, opts) 297 end
uri(addr = nil, absolute = true, add_script_name = true)
Generates the absolute URI for a given path in the app. Takes Rack routers and reverse proxies into account.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 301 def uri(addr = nil, absolute = true, add_script_name = true) 302 addr = addr.to_s if addr 303 return addr if addr =~ /\A[A-z][A-z0-9\+\.\-]*:/ 304 uri = if absolute 305 h = if @env.has_key?("HTTP_X_FORWARDED_HOST") || port != (ssl? ? 443 : 80) 306 host_with_port 307 else 308 host 309 end 310 ["http#{'s' if ssl?}://#{h}"] 311 else 312 [''] 313 end 314 uri << script_name.to_s if add_script_name 315 uri << (addr || path_info) 316 File.join(uri) 317 end