class Rewrite < ClientRedirect
- Inherits from
ClientRedirect
Inherited Methods
Rewrite requests that match the given pattern to a single destination.
Definitions
def initialize(app, patterns, status: 301)
Initialize exact-path redirections.
Signature
-
parameter
appInterface(:call) The downstream application.
-
parameter
patternsHash The path rewrite patterns.
-
parameter
statusInteger The status.
Implementation
def initialize(app, patterns, status: 301)
@patterns = patterns
super(app, status: status)
end
def freeze
Freeze this object and its internal state.
Signature
-
returns
self This object.
Implementation
def freeze
return self if frozen?
@patterns.freeze
return super
end
def [](path)
Redirect a path found in the rewrite map.
Signature
-
parameter
pathString The normalized request path.
-
returns
Protocol::HTTP::Response | Nil The redirect response when the path is mapped.
Implementation
def [] path
if location = @patterns[path]
return redirect(location)
end
end