class DirectoryIndex < ClientRedirect
- Inherits from
ClientRedirect
Inherited Methods
Redirect urls that end with a /, e.g. directories.
Definitions
def initialize(app, index: "index")
Initialize directory-index redirection.
Signature
-
parameter
appInterface(:call) The downstream application.
-
parameter
indexInteger The index.
Implementation
def initialize(app, index: "index")
@index = index
super(app)
end
def freeze
Freeze this object and its internal state.
Signature
-
returns
self This object.
Implementation
def freeze
return self if frozen?
@index.freeze
return super
end
def [](path)
Redirect a directory path to its index path.
Signature
-
parameter
pathString The normalized request path.
-
returns
Protocol::HTTP::Response | Nil The redirect response when the path ends with
/.
Implementation
def [] path
if path.end_with?("/")
return redirect(path + @index)
end
end