Class: Impression::FileTree
- Defined in:
- lib/impression/file_tree.rb
Overview
FileTree implements a resource that maps to a static file hierarchy.
Direct Known Subclasses
Constant Summary
Constants inherited from Resource
Resource::FIRST_PATH_SEGMENT_REGEXP
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#call(req) ⇒ void
Responds to a request.
-
#initialize(directory:, **props) ⇒ void
constructor
Initializes a
FileTreeresource. -
#render_from_path_info(req, path_info) ⇒ Object
Renders a response from the given response kind and path.
Methods inherited from Resource
#absolute_path, #add_child, #each, #html_response, #json_response, #render_tree_to_static_files, #route, #text_response, #to_proc
Constructor Details
#initialize(directory:, **props) ⇒ void
Initializes a FileTree resource.
15 16 17 18 19 |
# File 'lib/impression/file_tree.rb', line 15 def initialize(directory:, **props) super(**props) @directory = directory @path_info_cache = {} end |
Instance Method Details
#call(req) ⇒ void
This method returns an undefined value.
Responds to a request.
25 26 27 28 |
# File 'lib/impression/file_tree.rb', line 25 def call(req) path_info = get_path_info(req.resource_relative_path) render_from_path_info(req, path_info) end |
#render_from_path_info(req, path_info) ⇒ Object
Renders a response from the given response kind and path.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/impression/file_tree.rb', line 35 def render_from_path_info(req, path_info) case path_info[:kind] when :not_found req.respond(nil, ':status' => Qeweney::Status::NOT_FOUND) when :file render_file(req, path_info) else raise "Invalid path info kind #{kind.inspect}" end end |