Class: ImageOptim::ImagePath

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

Defined Under Namespace

Classes: Optimized

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert(path) ⇒ Object

Returns path if it is already an instance of this class otherwise new instance



58
59
60
# File 'lib/image_optim/image_path.rb', line 58

def self.convert(path)
  path.is_a?(self) ? path : new(path)
end

Instance Method Details

#copy(dst) ⇒ Object

Copy file to dest preserving attributes



35
36
37
# File 'lib/image_optim/image_path.rb', line 35

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

#formatObject

Get format using ImageSize



51
52
53
54
55
# File 'lib/image_optim/image_path.rb', line 51

def format
  if image_meta = ImageMeta.for_path(self)
    image_meta.format
  end
end

#replace(src) ⇒ Object

Atomic replace src with self



40
41
42
43
44
45
46
47
48
# File 'lib/image_optim/image_path.rb', line 40

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

#temp_path(*args, &block) ⇒ Object

Get temp path for this file with same extension



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

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