Class: Otto::Core::StaticMounts::StaticMount
- Inherits:
-
Struct
- Object
- Struct
- Otto::Core::StaticMounts::StaticMount
- Defined in:
- lib/otto/core/static_mounts.rb
Overview
One registered mount. prefix is the normalized URL prefix ('' for a
root mount), root the canonical directory, files the Rack::Files
instance rooted there. Instances are frozen at construction.
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#display_prefix ⇒ Object
Prefix as an operator would write it ('/' for a root mount).
-
#relative_path_for(path) ⇒ String?
Request-relative path under this mount, or nil when
pathis not beneath the prefix.
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files
42 43 44 |
# File 'lib/otto/core/static_mounts.rb', line 42 def files @files end |
#prefix ⇒ Object
Returns the value of attribute prefix
42 43 44 |
# File 'lib/otto/core/static_mounts.rb', line 42 def prefix @prefix end |
#root ⇒ Object
Returns the value of attribute root
42 43 44 |
# File 'lib/otto/core/static_mounts.rb', line 42 def root @root end |
Instance Method Details
#display_prefix ⇒ Object
Prefix as an operator would write it ('/' for a root mount).
58 59 60 |
# File 'lib/otto/core/static_mounts.rb', line 58 def display_prefix prefix.empty? ? '/' : prefix end |
#relative_path_for(path) ⇒ String?
Request-relative path under this mount, or nil when path is not
beneath the prefix. The prefix itself (the directory) never matches:
a mount serves files, not directory listings.
49 50 51 52 53 54 55 |
# File 'lib/otto/core/static_mounts.rb', line 49 def relative_path_for(path) if prefix.empty? path elsif path.start_with?("#{prefix}/") path[(prefix.length + 1)..] end end |