Class: ImageOptim::CachePath

Inherits:
Path
  • Object
show all
Defined in:
lib/image_optim/cache_path.rb

Overview

ImageOptiom::Path with a non self destructing #replace method

Constant Summary

Constants inherited from Path

Path::NULL

Instance Method Summary collapse

Methods inherited from Path

convert, #copy, #copy_metadata, #image_format, #move, #temp_path

Instance Method Details

#replace(dst) ⇒ Object

Atomic replace dst with self



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/image_optim/cache_path.rb', line 9

def replace(dst)
  dst = self.class.convert(dst)
  tmpdir = [dirname, Path.new(Dir.tmpdir)].find do |dir|
    dir.same_dev?(dst.dirname)
  end
  dst.temp_path_with_tmp_ext(tmpdir || dst.dirname) do |temp|
    copy(temp)
    dst.(temp)
    temp.rename(dst.to_s)
  end
end