Object
An instance of this class is supposed to provide similar methods to the class methods of Dir itself.
Fairly complete - like zip/zipfilesystem's implementation, i provide everything except chroot and glob. glob could be done with a glob to regex conversion, and then simply match in the entries array... although recursive glob complicates that somewhat.
Dir.chroot, Dir.glob, Dir.[], and Dir.tmpdir is the complete list of methods still missing.
# File lib/ole/storage/file_system.rb, line 288 def chdir orig_path # make path absolute, squeeze slashes, and remove trailing slash path = @ole.file.expand_path(orig_path).squeeze('/').sub(/\/$/, '') # this is just for the side effects of the exceptions if invalid dirent_from_path path, orig_path if block_given? old_pwd = @pwd begin @pwd = path yield ensure @pwd = old_pwd end else @pwd = path 0 end end
# File lib/ole/storage/file_system.rb, line 307 def entries path dirent = dirent_from_path path # Not sure about adding on the dots... entries = ]. ..] + dirent.children.map(&:name) # do some checks about un-reachable files seen = {} entries.each do |n| Log.warn "inaccessible file (filename contains slash) - #{n.inspect}" if n['/'] Log.warn "inaccessible file (duplicate filename) - #{n.inspect}" if seen[n] seen[n] = true end entries end
# File lib/ole/storage/file_system.rb, line 321 def foreach path, &block entries(path).each(&block) end
# File lib/ole/storage/file_system.rb, line 325 def mkdir path parent_path, basename = File.split @ole.file.expand_path(path) # note that we will complain about the full path despite accessing # the parent path. this is consistent with ::Dir parent = dirent_from_path parent_path, path # now, we first should ensure that it doesn't already exist # either as a file or a directory. raise Errno::EEXIST, path if parent/basename parent << Dirent.new(@ole, :type => :dir, :name => basename) 0 end
as for file, explicit alias to inhibit block
# File lib/ole/storage/file_system.rb, line 276 def new path open path end
# File lib/ole/storage/file_system.rb, line 269 def open path dir = Dir.new path, entries(path) return dir unless block_given? yield dir end
pwd is always stored without the trailing slash. we handle the root case here
# File lib/ole/storage/file_system.rb, line 282 def pwd return '/' if @pwd.empty? @pwd end
Generated with the Darkfish Rdoc Generator 2.