class Rack::Joint::RedirectInterface
Attributes
old_host[R]
old_path[R]
request_query[R]
request_scheme[R]
scheme[R]
Public Class Methods
new(request, old_host, old_path, &block)
click to toggle source
# File lib/rack/joint/redirect_interface.rb, line 8 def initialize(request, old_host, old_path, &block) @status = 301 @scheme = nil @request_query = request.query_string @request_scheme = request.scheme @old_host = old_host @old_path = old_path || request.path_info instance_exec(&block) end
Public Instance Methods
apply!()
click to toggle source
@return [Array] Return response given parameters in `config.ru`.
# File lib/rack/joint/redirect_interface.rb, line 19 def apply! @scheme ||= request_scheme @new_host ||= old_host @new_path ||= old_path old_url = UrlBuilder.new(request_scheme, request_query, old_host, old_path).build new_location = UrlBuilder.new(scheme, request_query, @new_host, @new_path).build if old_url == new_location raise BadRedirectError.new('Redirect URL has been declared the same as current URL.') end [@status, { 'Location' => new_location, 'Content-Type' => 'text/html', 'Content-Language' => '0' }, ["Redirect from: #{old_url}"]] end
Private Instance Methods
new_host(host)
click to toggle source
@param host [String] `new_host` parameter to redirect hostname in `config.ru`. @return [String] Return hostname where redirects to.
# File lib/rack/joint/redirect_interface.rb, line 64 def new_host(host) @new_host = host end
ssl(flag)
click to toggle source
@param flag [Boolean] @return [String] `http` or `https`
# File lib/rack/joint/redirect_interface.rb, line 35 def ssl(flag) @scheme = if flag 'https' else 'http' end end
status(status)
click to toggle source
@param status [Integer] `status` parameter when redirecting in `config.ru`. @return [Integer] Return status code.
# File lib/rack/joint/redirect_interface.rb, line 46 def status(status) @status = case status when 302 302 when 303 303 when 307 307 when 308 308 else 301 end end
to(path)
click to toggle source
@param path [String] `to` parameter to redirect path in `config.ru` @return [String] Return pathname where redirects to.
# File lib/rack/joint/redirect_interface.rb, line 70 def to(path) @new_path = path end