Class: Utopia::Redirection::Moved

Inherits:
ClientRedirect show all
Defined in:
lib/utopia/redirection.rb

Overview

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

Instance Attribute Summary

Attributes inherited from ClientRedirect

#max_age, #status

Instance Method Summary collapse

Methods inherited from ClientRedirect

#cache_control, #call, #freeze, #headers, #redirect

Constructor Details

#initialize(app, pattern, prefix, status: 301, flatten: false) ⇒ Moved

Returns a new instance of Moved.



165
166
167
168
169
170
171
172
173
# File 'lib/utopia/redirection.rb', line 165

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

Instance Method Details

#[](path) ⇒ Object



175
176
177
178
179
180
181
182
183
# File 'lib/utopia/redirection.rb', line 175

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