Class: Cabi::List

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

Class Method Summary collapse

Class Method Details

.list(id, opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/list.rb', line 4

def self.list(id, opts={})
  ls    = []
  path  = id.gsub( DELIMITER, '/')

  Dir.glob( "#{Cabi.data_dir}/#{path}") do |item|
    next if item == '.' or item == '..'

    i = opts[:full_path] ? item : Cabi.path_to_id(item)
    ls << [ i, File.directory?(item) ? "dir" : "file", File.basename(item) ]
  end

  ls.sort_by!{ |f| f[1] } if opts[:dirs_first] # "dir" < "file" 
  ls
end