Class: ImageOptim::ImagePath

Inherits:
FSPath
  • Object
show all
Defined in:
lib/image_optim/image_path.rb

Instance Method Summary collapse

Instance Method Details

#copy(dst) ⇒ Object

Copy file to dest preserving attributes



15
16
17
# File 'lib/image_optim/image_path.rb', line 15

def copy(dst)
  FileUtils.copy_file(self, dst, true)
end

#formatObject

Get format using ImageSize



30
31
32
# File 'lib/image_optim/image_path.rb', line 30

def format
  open{ |f| ImageSize.new(f) }.format
end

#replace(src) ⇒ Object

Atomic replace src with self



20
21
22
23
24
25
26
27
# File 'lib/image_optim/image_path.rb', line 20

def replace(src)
  src = self.class.new(src)
  src.temp_path(src.dirname) do |temp|
    src.copy(temp)
    temp.write(read)
    temp.rename(src)
  end
end

#temp_path(*args, &block) ⇒ Object

Get temp path for this file with same extension



9
10
11
12
# File 'lib/image_optim/image_path.rb', line 9

def temp_path(*args, &block)
  ext = extname
  self.class.temp_file_path([basename(ext), ext], *args, &block)
end