Innate::Helper::Redirect

Public Instance Methods

raw_redirect(target, options = {}, &block) click to toggle source
    # File lib/innate/helper/redirect.rb, line 59
59:       def raw_redirect(target, options = {}, &block)
60:         header = response.header.merge('Location' => target.to_s)
61:         status = options[:status] || 302
62:         body   = options[:body] || redirect_body(target)
63: 
64:         Log.debug "Redirect to: #{target}"
65:         throw(:redirect, Response.new(body, status, header, &block))
66:       end
redirect(target, options = {}) click to toggle source

target should be anything responding to #. To check or modify the URI the redirect will go to you may pass a block, the result value of the block is ignored:

  redirect("/"){|uri| uri.scheme = 'http' }
  redirect("/"){|uri| uri.host = 'secure.com' if uri.scheme =~ /s/ }

options may contain:

  :scheme => "http" | "https" | "ftp" | ...
  :host   => "localhost" | "foo.com" | "123.123.123.123" | ...
  :port   => 7000 | "80" | 80 | ...

  :status => 302 | 300 | 303 | ...
  :body   => "This is a redirect, hold on while we teleport" | ...

  :raw!   => true | false | nil | ...

Note that all options are optional and you may just pass a target.

    # File lib/innate/helper/redirect.rb, line 38
38:       def redirect(target, options = {})
39:         target = target.to_s
40: 
41:         case target
42:         when /^http/, /^\//
43:           uri = URI(target)
44:         else
45:           uri = URI("/#{target}")
46:         end
47: 
48:         uri.scheme ||= options[:scheme] || request.scheme
49:         uri.host   ||= options[:host]   || request.host
50:         uri.port   ||= options[:port]   || request.port
51: 
52:         uri = URI(uri.to_s)
53: 
54:         yield(uri) if block_given?
55: 
56:         raw_redirect(uri, options)
57:       end
redirect_body(target) click to toggle source
    # File lib/innate/helper/redirect.rb, line 68
68:       def redirect_body(target)
69:         "You are being redirected, please follow this link to: " +
70:           "<a href='#{target}'>#{h target}</a>!"
71:       end
redirect_referer(fallback = Innate.options.prefix) click to toggle source
Alias for: redirect_referrer
redirect_referrer(fallback = Innate.options.prefix) click to toggle source
    # File lib/innate/helper/redirect.rb, line 73
73:       def redirect_referrer(fallback = Innate.options.prefix)
74:         if (referer = request.env['HTTP_REFERER']) && (url = request.url)
75:           referer_uri, request_uri = URI(referer), URI(url)
76: 
77:           redirect(referer) unless referer_uri == request_uri
78:         end
79: 
80:         redirect(fallback)
81:       end
Also aliased as: redirect_referer
respond(body, status = 200, header = {}) click to toggle source
    # File lib/innate/helper/redirect.rb, line 4
 4:       def respond(body, status = 200, header = {})
 5:         response.write body
 6:         response.status = status
 7:         header['Content-Type'] ||= Response.mime_type
 8:         header.each{|key, value| response[key] = value }
 9: 
10:         throw(:respond, response)
11:       end
respond!(body, status = 200, header = {}) click to toggle source
    # File lib/innate/helper/redirect.rb, line 13
13:       def respond!(body, status = 200, header = {})
14:         header['Content-Type'] ||= Response.mime_type
15:         throw(:respond, Response.new(body, status, header))
16:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.