Method: Stud::Temporary#directory

Defined in:
lib/stud/temporary.rb

#directory(prefix = DEFAULT_PREFIX, &block) ⇒ Object

Make a temporary directory.

If given a block, the directory path is given to the block. WHen the block finishes, the directory and all its contents will be deleted.

If no block given, it will return the path to a newly created directory. You are responsible for then cleaning up.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stud/temporary.rb', line 45

def directory(prefix=DEFAULT_PREFIX, &block)
  path = pathname(prefix)
  Dir.mkdir(path)

  if block_given?
    begin
      block.call(path)
    ensure
      FileUtils.rm_r(path)
    end
  else
    return path
  end
end