Sha256: 25ae96a67f4ca9803361b527a160a9d5f1fdc10b64bcb55aedd729a3178cfb43
Contents?: true
Size: 541 Bytes
Versions: 1
Compression:
Stored size: 541 Bytes
Contents
# frozen_string_literal: true require 'atomos/version' module Atomos module_function def atomic_write(dest, contents = nil, tmpdir: Dir.tmpdir, &block) unless contents.nil? ^ block.nil? raise ArgumentError, 'must provide either contents or a block' end require 'tempfile' Tempfile.open(".atomos.#{File.basename(dest)}", tmpdir) do |tmpfile| if contents tmpfile << contents else retval = yield tmpfile end File.rename(tmpfile.path, dest) retval end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
atomos-0.1.0 | lib/atomos.rb |