class Moved < ClientRedirect

Inherits from
ClientRedirect

Inherited Methods

From Utopia::Redirection::ClientRedirect:

Rewrite requests that match the given pattern to a new prefix.

Definitions

def initialize(app, pattern, prefix, status: 301, flatten: false)

Initialize prefix redirection behavior.

Signature

parameter app Interface(:call)

The downstream application.

parameter pattern Regexp

The path pattern.

parameter prefix String

The prefix.

parameter status Integer

The status.

parameter flatten bool

Whether to flatten the rewritten path.

Implementation

def initialize(app, pattern, prefix, status: 301, flatten: false)
	@pattern = pattern
	@prefix = prefix
	@flatten = flatten
	
	super(app, status: status)
end

def freeze

Freeze this object and its internal state.

Signature

returns self

This object.

Implementation

def freeze
	return self if frozen?
	
	@pattern.freeze
	@prefix.freeze
	@flatten.freeze
	
	return super
end

def [](path)

Redirect a matching path to the configured prefix.

Signature

parameter path String

The normalized request path.

returns Protocol::HTTP::Response | Nil

The redirect response when the pattern matches.

Implementation

def [] path
	if path.start_with?(@pattern)
		if @flatten
			return redirect(@prefix)
		else
			return redirect(path.sub(@pattern, @prefix))
		end
	end
end