Class: Utopia::Redirection::Rewrite

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

Overview

Rewrite requests that match the given pattern to a single destination.

Instance Attribute Summary

Attributes inherited from ClientRedirect

#max_age, #status

Instance Method Summary collapse

Methods inherited from ClientRedirect

#cache_control, #call, #make_headers, #redirect

Constructor Details

#initialize(app, patterns, status: 301) ⇒ Rewrite

Initialize exact-path redirections.



16
17
18
19
20
# File 'lib/utopia/redirection/rewrite.rb', line 16

def initialize(app, patterns, status: 301)
	@patterns = patterns
	
	super(app, status: status)
end

Instance Method Details

#[](path) ⇒ Object

Redirect a path found in the rewrite map.



35
36
37
38
39
# File 'lib/utopia/redirection/rewrite.rb', line 35

def [] path
	if location = @patterns[path]
		return redirect(location)
	end
end

#freezeObject

Freeze this object and its internal state.



24
25
26
27
28
29
30
# File 'lib/utopia/redirection/rewrite.rb', line 24

def freeze
	return self if frozen?
	
	@patterns.freeze
	
	return super
end