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_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
10 11 12 13 14 15 16 17 |
# File 'lib/rack/joint/redirect_interface.rb', line 10 def initialize(request, old_host, old_path, &block) @status = 301 @scheme = nil @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.
9 10 11 |
# File 'lib/rack/joint/redirect_interface.rb', line 9 def old_host @old_host end |
#old_path ⇒ Object (readonly)
Returns the value of attribute old_path.
9 10 11 |
# File 'lib/rack/joint/redirect_interface.rb', line 9 def old_path @old_path end |
#request_scheme ⇒ Object (readonly)
Returns the value of attribute request_scheme.
9 10 11 |
# File 'lib/rack/joint/redirect_interface.rb', line 9 def request_scheme @request_scheme end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
9 10 11 |
# File 'lib/rack/joint/redirect_interface.rb', line 9 def scheme @scheme end |
Instance Method Details
#apply! ⇒ Array
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rack/joint/redirect_interface.rb', line 20 def apply! @scheme ||= request_scheme @new_host ||= old_host @new_path ||= old_path old_url = build_uri(request_scheme, old_host, old_path) new_location = build_uri(scheme, @new_host, @new_path) 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 |