Class: Dir
Class Method Summary collapse
-
.dirname(path) ⇒ Object
Same as File.dirname, but returns an empty string instead of ‘.’.
-
.stat_list(path, stat = false, skip = nil) ⇒ [String, File::Stat, String]
Iterates over a directory, yielding an array with the File::Stat entry for each file/directory in the requested directory.
- .tmpdir ⇒ Object
Class Method Details
.dirname(path) ⇒ Object
Same as File.dirname, but returns an empty string instead of ‘.’
275 276 277 |
# File 'lib/amp/support/support.rb', line 275 def self.dirname(path) File.dirname(path) == '.' ? '' : File.dirname(path) end |
.stat_list(path, stat = false, skip = nil) ⇒ [String, File::Stat, String]
Iterates over a directory, yielding an array with the File::Stat entry for each file/directory in the requested directory.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/amp/support/support.rb', line 246 def self.stat_list path, stat=false, skip=nil result = [] prefix = path prefix += File::SEPARATOR unless prefix =~ /#{File::SEPARATOR}$/ names = Dir.entries(path).select {|i| i != "." && i != ".."}.sort names.each do |fn| st = File.lstat(prefix + fn) return [] if fn == skip && File.directory?(prefix + fn) if st.ftype && st.ftype !~ /unknown/ newval = [fn, st.ftype, st] else newval = [fn, st.ftype] end result << newval yield newval if block_given? end result end |
.tmpdir ⇒ Object
265 266 267 268 269 |
# File 'lib/amp/support/support.rb', line 265 def self.tmpdir "/tmp" # default, but it should never ever be used! # i mean it's ok if it is # but i'd be caught off guard if this ends up being used in the code end |