Class: Utopia::Redirection::Moved
- Inherits:
-
ClientRedirect
- Object
- Protocol::HTTP::Middleware
- ClientRedirect
- Utopia::Redirection::Moved
- Defined in:
- lib/utopia/redirection/moved.rb
Overview
Rewrite requests that match the given pattern to a new prefix.
Instance Attribute Summary
Attributes inherited from ClientRedirect
Instance Method Summary collapse
-
#[](path) ⇒ Object
Redirect a matching path to the configured prefix.
-
#freeze ⇒ Object
Freeze this object and its internal state.
-
#initialize(app, pattern, prefix, status: 301, flatten: false) ⇒ Moved
constructor
Initialize prefix redirection behavior.
Methods inherited from ClientRedirect
#cache_control, #call, #make_headers, #redirect
Constructor Details
#initialize(app, pattern, prefix, status: 301, flatten: false) ⇒ Moved
Initialize prefix redirection behavior.
18 19 20 21 22 23 24 |
# File 'lib/utopia/redirection/moved.rb', line 18 def initialize(app, pattern, prefix, status: 301, flatten: false) @pattern = pattern @prefix = prefix @flatten = flatten super(app, status: status) end |
Instance Method Details
#[](path) ⇒ Object
Redirect a matching path to the configured prefix.
41 42 43 44 45 46 47 48 49 |
# File 'lib/utopia/redirection/moved.rb', line 41 def [] path if path.start_with?(@pattern) if @flatten return redirect(@prefix) else return redirect(path.sub(@pattern, @prefix)) end end end |
#freeze ⇒ Object
Freeze this object and its internal state.
28 29 30 31 32 33 34 35 36 |
# File 'lib/utopia/redirection/moved.rb', line 28 def freeze return self if frozen? @pattern.freeze @prefix.freeze @flatten.freeze return super end |