Method: Files.create

Defined in:
lib/files.rb

.create(options = default_options, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/files.rb', line 17

def self.create options = default_options, &block
  require 'tmpdir'
  require 'fileutils'

  name = options[:name]
  root = Dir::tmpdir

  # if the user specified a root directory (instead of default Dir.tmpdir)
  if options[:path]
    # then we will create their directory for them (test context-be friendly)
    root = options[:path]
    FileUtils::mkdir_p(root)
    # if they gave relative path, this forces absolute
    root = File.expand_path(root)
  end

  path = File.join(root, "#{name}_#{Time.now.to_i}_#{rand(1000)}")
  Files.new path, block, options
end