Class: Rack::Bunto::FileHandler
- Inherits:
-
Object
- Object
- Rack::Bunto::FileHandler
- Defined in:
- lib/rack/bunto/filehandler.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#get_filename(path) ⇒ Object
Returns the full file system path of the file corresponding to the given URL path, or
nil
if no corresponding file exists. -
#initialize(root, files = nil) ⇒ FileHandler
constructor
Initializes a FileHandler for a given root directory (for testing only: use a given array of filenames,
files
). - #update ⇒ Object
Constructor Details
#initialize(root, files = nil) ⇒ FileHandler
Initializes a FileHandler for a given root directory (for testing only: use a given array of filenames, files
).
9 10 11 12 |
# File 'lib/rack/bunto/filehandler.rb', line 9 def initialize(root, files = nil) @root = ::File.(root) @files = files || get_file_list end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
5 6 7 |
# File 'lib/rack/bunto/filehandler.rb', line 5 def files @files end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/rack/bunto/filehandler.rb', line 5 def root @root end |
Instance Method Details
#empty? ⇒ Boolean
14 15 16 |
# File 'lib/rack/bunto/filehandler.rb', line 14 def empty? @files.empty? end |
#get_filename(path) ⇒ Object
Returns the full file system path of the file corresponding to the given URL path, or nil
if no corresponding file exists.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rack/bunto/filehandler.rb', line 24 def get_filename(path) fullpath = ::File.join(@root, path) if fullpath.end_with?("/") normalized = fullpath + "index.html" elsif !@files.include?(fullpath) normalized = fullpath + "/index.html" else normalized = fullpath end if @files.include?(normalized) filename = normalized else filename = nil end filename end |
#update ⇒ Object
18 19 20 |
# File 'lib/rack/bunto/filehandler.rb', line 18 def update @files = get_file_list end |