Class: Rack::Joint::RedirectInterface
- Inherits:
-
Object
- Object
- Rack::Joint::RedirectInterface
- Defined in:
- lib/rack/joint/redirect_interface.rb
Instance Attribute Summary collapse
-
#old_host ⇒ Object
readonly
Returns the value of attribute old_host.
-
#old_path ⇒ Object
readonly
Returns the value of attribute old_path.
-
#request_query ⇒ Object
readonly
Returns the value of attribute request_query.
-
#request_scheme ⇒ Object
readonly
Returns the value of attribute request_scheme.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
Instance Method Summary collapse
-
#apply! ⇒ Array
Return response given parameters in
config.ru. -
#initialize(request, old_host, old_path, &block) ⇒ RedirectInterface
constructor
A new instance of RedirectInterface.
Constructor Details
#initialize(request, old_host, old_path, &block) ⇒ RedirectInterface
Returns a new instance of RedirectInterface.
8 9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#old_host ⇒ Object (readonly)
Returns the value of attribute old_host.
7 8 9 |
# File 'lib/rack/joint/redirect_interface.rb', line 7 def old_host @old_host end |
#old_path ⇒ Object (readonly)
Returns the value of attribute old_path.
7 8 9 |
# File 'lib/rack/joint/redirect_interface.rb', line 7 def old_path @old_path end |
#request_query ⇒ Object (readonly)
Returns the value of attribute request_query.
7 8 9 |
# File 'lib/rack/joint/redirect_interface.rb', line 7 def request_query @request_query end |
#request_scheme ⇒ Object (readonly)
Returns the value of attribute request_scheme.
7 8 9 |
# File 'lib/rack/joint/redirect_interface.rb', line 7 def request_scheme @request_scheme end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
7 8 9 |
# File 'lib/rack/joint/redirect_interface.rb', line 7 def scheme @scheme end |
Instance Method Details
#apply! ⇒ Array
Return response given parameters in config.ru.
19 20 21 22 23 24 25 26 27 28 29 |
# 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 |