Class: Ferver::FileList
- Inherits:
-
Object
- Object
- Ferver::FileList
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/ferver/file_list.rb
Class Method Summary collapse
-
.path_for_file(directory, file_name) ⇒ Object
Return an absolute path to a ‘file_name` in the `directory`.
Instance Method Summary collapse
- #all ⇒ Object
-
#file_by_id(id) ⇒ Object
Filename by its index.
-
#file_id_valid?(file_id) ⇒ Boolean
Is the file id a valid id for Ferver to serve.
-
#initialize(path) ⇒ FileList
constructor
Create a new instance with a path.
Constructor Details
#initialize(path) ⇒ FileList
Create a new instance with a path
14 15 16 17 18 19 20 21 |
# File 'lib/ferver/file_list.rb', line 14 def initialize(path) fail ArgumentError, 'No path is specified' if path.empty? fail DirectoryNotFoundError unless Dir.exist?(path) @files = [] @configured_file_path = File.(path) find_files end |
Class Method Details
.path_for_file(directory, file_name) ⇒ Object
Return an absolute path to a ‘file_name` in the `directory`
25 26 27 |
# File 'lib/ferver/file_list.rb', line 25 def self.path_for_file(directory, file_name) File.join(directory, file_name) end |
Instance Method Details
#all ⇒ Object
41 42 43 |
# File 'lib/ferver/file_list.rb', line 41 def all files end |
#file_by_id(id) ⇒ Object
Filename by its index
37 38 39 |
# File 'lib/ferver/file_list.rb', line 37 def file_by_id(id) files.fetch(id) end |
#file_id_valid?(file_id) ⇒ Boolean
Is the file id a valid id for Ferver to serve
31 32 33 |
# File 'lib/ferver/file_list.rb', line 31 def file_id_valid?(file_id) file_id < files.size end |