Module: Atomos
- Defined in:
- lib/atomos.rb,
lib/atomos/version.rb
Constant Summary collapse
- VERSION =
File.read(File.('../../../VERSION', __FILE__))
Class Method Summary collapse
Class Method Details
.atomic_write(dest, contents = nil, tmpdir: Dir.tmpdir, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/atomos.rb', line 8 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 |