Class: Utopia::Redirection::Moved

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

Instance Attribute Summary

Attributes inherited from Redirection

#max_age, #status

Instance Method Summary collapse

Methods inherited from Redirection

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

Constructor Details

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

Returns a new instance of Moved.



155
156
157
158
159
160
161
162
163
# File 'lib/utopia/redirection.rb', line 155

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



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

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