Sha256: ac88b1052dcd01aa267d1c5961795f2b87f8856a32abc640a3d455f0108d9dab

Contents?: true

Size: 852 Bytes

Versions: 85

Compression:

Stored size: 852 Bytes

Contents

def new_temp_dir
  #Get a new temporary directory
  temp = Tempfile.new SecureRandom.hex
  path = temp.path
  temp.close!

  FileUtils.mkdir_p path
  return path
end

class Tempdir
  attr_accessor :path

  def initialize
    #Create a new directory
    @path = new_temp_dir
  end

  def [](rel)
    return TempDirFile.new(@path, rel)
  end

  def cd
    Dir.chdir @path do
      yield
    end
  end
end

class TempDirFile
  def initialize path, rel
    @path = path
    @rel = rel
  end

  def puts str

    Dir.chdir @path do
      #Create all folders
      FileUtils.mkdir_p File.dirname(@rel)

      FileUtils.touch(@rel)

      open(@rel, "a") do |f|
        f.write str
      end
    end
  end
end

def dirs
  Dir["**/*"].select{|e| File.directory?(e)}
end

def files
  Dir["{*,.*}"].select{|e| File.file?(e)} #Match dotfiles and normal files
end

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
flok-0.0.105 spec/lib/temp_dir.rb
flok-0.0.103 spec/lib/temp_dir.rb
flok-0.0.102 spec/lib/temp_dir.rb
flok-0.0.101 spec/lib/temp_dir.rb
flok-0.0.100 spec/lib/temp_dir.rb
flok-0.0.99 spec/lib/temp_dir.rb
flok-0.0.98 spec/lib/temp_dir.rb
flok-0.0.97 spec/lib/temp_dir.rb
flok-0.0.96 spec/lib/temp_dir.rb
flok-0.0.95 spec/lib/temp_dir.rb
flok-0.0.94 spec/lib/temp_dir.rb
flok-0.0.93 spec/lib/temp_dir.rb
flok-0.0.92 spec/lib/temp_dir.rb
flok-0.0.91 spec/lib/temp_dir.rb
flok-0.0.90 spec/lib/temp_dir.rb
flok-0.0.89 spec/lib/temp_dir.rb
flok-0.0.88 spec/lib/temp_dir.rb
flok-0.0.87 spec/lib/temp_dir.rb
flok-0.0.86 spec/lib/temp_dir.rb
flok-0.0.85 spec/lib/temp_dir.rb