Class: FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/file_browser_manager/file_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject

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