Class AtomicFile
In: lib/more/facets/atomicfile.rb
Parent: File

This is a precursor to the possibility of a more extensive Atomic File I/O system. For now it simply provides a means for atomic file writing.

Methods

write  

Public Class methods

Write to a file atomically. Useful for situations where you don‘t want other processes or threads to see half-written files.

  AtomicFile.write("tmp/important.file") do |file|
    file.write("hello")
  end

If your temporary directory is not on the same filesystem as the file you‘re trying to write, you can provide a different temporary directory.

  AtomicFile.write("tmp/something.important", "tmp") do |file|
    file.write("hello")
  end

[Validate]