Class: FileManager
- Inherits:
-
Object
- Object
- FileManager
- Defined in:
- lib/file_browser_manager/file_manager.rb
Instance Attribute Summary collapse
-
#root_path ⇒ Object
Returns the value of attribute root_path.
Instance Method Summary collapse
-
#initialize(root_path) ⇒ FileManager
constructor
A new instance of FileManager.
- #list_folder(path = nil) ⇒ Object
Constructor Details
#initialize(root_path) ⇒ FileManager
Returns a new instance of FileManager.
5 6 7 |
# File 'lib/file_browser_manager/file_manager.rb', line 5 def initialize root_path @root_path = root_path end |
Instance Attribute Details
#root_path ⇒ Object
Returns the value of attribute root_path.
3 4 5 |
# File 'lib/file_browser_manager/file_manager.rb', line 3 def root_path @root_path end |
Instance Method Details
#list_folder(path = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/file_browser_manager/file_manager.rb', line 9 def list_folder(path = nil) elements = Dir.glob([root_path, path, '*'].compact.join('/')) list = elements.map do |element| name = File.basename element {name: name, path: [path, name].compact.join('/'), type: File.directory?(element) ? 'dir' : 'file'} end return list.sort_by{ |element| element[:name] }.sort_by { |element| element[:type] } end |