Class: Dir

Inherits:
Object show all
Defined in:
lib/amp/support/support.rb

Class Method Summary collapse

Class Method Details

.dirname(path) ⇒ Object

Same as File.dirname, but returns an empty string instead of ‘.’

Parameters:

  • path (String)

    the path to get the directory 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.

Parameters:

  • path (String)

    the path to iterate over

  • stat (Boolean) (defaults to: false)

    should we retrieve stat information?

  • skip (String) (defaults to: nil)

    a filename to always skip

Returns:



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

.tmpdirObject



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