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 = , &block require 'tmpdir' require 'fileutils' name = [:name] root = Dir::tmpdir # if the user specified a root directory (instead of default Dir.tmpdir) if [:path] # then we will create their directory for them (test context-be friendly) root = [:path] FileUtils::mkdir_p(root) # if they gave relative path, this forces absolute root = File.(root) end path = File.join(root, "#{name}_#{Time.now.to_i}_#{rand(1000)}") Files.new path, block, end |