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.



148
149
150
151
152
153
154
155
156
# File 'lib/utopia/redirection.rb', line 148

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



158
159
160
161
162
163
164
165
166
# File 'lib/utopia/redirection.rb', line 158

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