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 collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Attributes inherited from Resource
Instance Method Summary collapse
-
#call(req) ⇒ void
Responds to a request.
-
#initialize(directory: nil, **props, &block) ⇒ void
constructor
Initializes a ‘FileTree` resource.
-
#render_from_path_info(req, path_info) ⇒ void
Renders a response from the given path info.
Methods inherited from Resource
#absolute_path, #add_child, #each, #html_response, #json_response, #remount, #remove_child, #render_tree_to_static_files, #route, #text_response, #to_proc
Constructor Details
#initialize(directory: nil, **props, &block) ⇒ void
Initializes a ‘FileTree` resource.
17 18 19 20 21 |
# File 'lib/impression/file_tree.rb', line 17 def initialize(directory: nil, **props, &block) super(**props, &block) @directory = directory @path_info_cache = {} end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
11 12 13 |
# File 'lib/impression/file_tree.rb', line 11 def directory @directory end |
Instance Method Details
#call(req) ⇒ void
This method returns an undefined value.
Responds to a request.
27 28 29 30 31 32 |
# File 'lib/impression/file_tree.rb', line 27 def call(req) return super if @directory.nil? path_info = get_path_info(req.resource_relative_path) render_from_path_info(req, path_info) end |
#render_from_path_info(req, path_info) ⇒ void
This method returns an undefined value.
Renders a response from the given path info.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/impression/file_tree.rb', line 39 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 #{path_info[:kind].inspect}" end end |