class FMDir
Public Instance Methods
entries()
click to toggle source
Returns all entries in that directory
# File Entities/FilesManage.rb, line 67 def entries return [] unless parent != '' FMEntries.search_all_.select { |e| dir = e._directory dir._parent == parent && dir._name == name } end
path(*f)
click to toggle source
# File Entities/FilesManage.rb, line 56 def path(*f) p = [name] parent and p.unshift(parent) File.join(FMDirs.dir_base, *p, *f) end
sub_dirs()
click to toggle source
# File Entities/FilesManage.rb, line 62 def sub_dirs return FMDirs.search_by_parent(name) end
update_dirs()
click to toggle source
If it's an OS-directory, it adds all its subdirectories that are not yet stored.
# File Entities/FilesManage.rb, line 110 def update_dirs return if parent && parent != '' fdirs = [] Dir.glob(File.join(path, '*/')).each{|d| d = File.basename(d) if FMDirs.search_by_path(d, name) next end fdirs.push FMDirs.create(name: d, parent: name) } fdirs end
update_files()
click to toggle source
Searches for files that are not an entry yet, adds them and returns the array of new entries.
# File Entities/FilesManage.rb, line 77 def update_files # dputs_func ffiles = [] fentries = entries Dir.glob(File.join(path, '*')).each { |f| next if File.directory? f f = File.basename(f) if f !~ /\.file$/ dputs(3) { "Found file #{f}" } if fentries.select { |e| dputs(3) { "Checking with #{e._name} / #{e.file_name}" } e.file_name == f }.size == 0 f_sanitized = FMDirs.accents_replace(f) if f_sanitized != f File.rename(path(f), path(f_sanitized)) end dputs(3) { "Creating entry for #{f}/#{f_sanitized} with dir #{self.inspect}" } desc = '' if f.size > 16 desc = f desc.sub(/\..*?$/, '') end ffiles.push FMEntries.create(name: f_sanitized, url_file: "localhost://#{f_sanitized}", directory: self, tags: [], description: desc) end end } ffiles end