Class: FileSystem

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

Class Method Summary collapse

Class Method Details

.dir_info(dir, list_files = "true") ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/apis/filesystem_api.rb', line 31

def self.dir_info(dir, list_files = "true")
  ret = {}
  ret[:name] = File.basename(dir.path)
  ret[:path] = dir.path
  ret[:absolute_path] = File.absolute_path(dir.path)
  ret[:is_dir] = true
  if list_files
    files = []
    dir.each do |name|
      begin
        f = File.new("#{dir.path}/#{name}")
        files << file_info(f)
      rescue
        #puts "error"
        #puts e
      end
    end
    ret[:contents] = files
  end
  ret
end

.file_info(file) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/apis/filesystem_api.rb', line 53

def self.file_info(file)
  if Dir.exist?(file.path)
    d = Dir.new(file.path)
    return dir_info(d, false)
  end
  ret = {}
  ret[:name] = File.basename(file.path)
  ret[:path] = file.path
  ret[:absolute_path] = File.absolute_path(file.path)
  ret[:is_dir] = false
  ret[:bytes] = file.size
  ret[:client_mtime] = file.mtime
  ret[:modified] = file.ctime
  ret[:mime_type] = Rack::Mime.mime_type("." + file.path.split('.').last)
  #ret[:binary] = File.binary?(ret[:absolute_path])
  ret
end