Sha256: 5a438efe5a6e4bf6d83f293ffb80abe2c0e3f57f0f22e5c0e522ab2ed1fe717f
Contents?: true
Size: 567 Bytes
Versions: 13
Compression:
Stored size: 567 Bytes
Contents
module Spruz module Write # Write to a file atomically def write(filename, content = nil, mode = 'w') temp = File.new(filename + ".tmp.#$$.#{Time.now.to_f}", mode) if content.nil? and block_given? yield temp elsif !content.nil? temp.write content else raise ArgumentError, "either content or block argument required" end temp.close File.rename temp.path, filename ensure temp and !temp.closed? and temp.close File.file?(temp.path) and File.unlink temp.path end end end
Version data entries
13 entries across 13 versions & 1 rubygems