class Tumugi::AtomicFile
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/tumugi/atomic_file.rb, line 12 def initialize(path) @path = path end
Public Instance Methods
close()
click to toggle source
# File lib/tumugi/atomic_file.rb, line 31 def close if @temp_file @temp_file.flush move_to_final_destination(@temp_file) @temp_file.close @temp_file = nil end end
move_to_final_destination(temp_file)
click to toggle source
# File lib/tumugi/atomic_file.rb, line 40 def move_to_final_destination(temp_file) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end
open(&block)
click to toggle source
# File lib/tumugi/atomic_file.rb, line 18 def open(&block) if block_given? Tempfile.open(basename) do |fp| @temp_file = fp block.call(self) close end else @temp_file = Tempfile.open(basename) end self end
Private Instance Methods
basename()
click to toggle source
# File lib/tumugi/atomic_file.rb, line 46 def basename @basename ||= File.basename(@path) end