Module: Clamsy::FileSystemSupport

Included in:
Clamsy, BasePrinter, BundledFileConfig, TemplateOpenDoc
Defined in:
lib/clamsy/file_system_support.rb

Instance Method Summary collapse

Instance Method Details

#file_must_exist!(path, timeout = 0) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/clamsy/file_system_support.rb', line 10

def file_must_exist!(path, timeout=0)
  if timeout.zero?
    File.exists?(path) or raise_file_not_found_error(path)
  else
    0.upto(timeout.pred) {|i| File.exists?(path) ? (return true) : sleep(1) }
    raise_file_not_found_error(path)
  end
end

#tmp_file(basename = nil) ⇒ Object



24
25
26
27
# File 'lib/clamsy/file_system_support.rb', line 24

def tmp_file(basename = nil)
  basename ||= Digest::MD5.hexdigest(Time.now.to_s)
  ((@trashable_tmp_files ||= []) << Tempfile.new(basename))[-1]
end

#trash_tmp_filesObject



19
20
21
22
# File 'lib/clamsy/file_system_support.rb', line 19

def trash_tmp_files
  (@trashable_tmp_files || []).each {|f| f.path && f.unlink }
  @trashable_tmp_files = nil
end