class ImageOptim::ImagePath
FSPath with additional helpful methods
Public Class Methods
convert(path)
click to toggle source
Returns path if it is already an instance of this class otherwise new instance
# File lib/image_optim/image_path.rb, line 64 def self.convert(path) path.is_a?(self) ? path : new(path) end
Public Instance Methods
binread()
click to toggle source
Read binary data
# File lib/image_optim/image_path.rb, line 58 def binread open('rb', &:read) end
copy(dst)
click to toggle source
Copy file to dest preserving attributes
# File lib/image_optim/image_path.rb, line 36 def copy(dst) FileUtils.copy_file(self, dst, true) end
format()
click to toggle source
Get format using ImageSize
# File lib/image_optim/image_path.rb, line 52 def format image_meta = ImageMeta.for_path(self) image_meta && image_meta.format end
replace(src)
click to toggle source
Atomic replace src with self
# File lib/image_optim/image_path.rb, line 41 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)
click to toggle source
Get temp path for this file with same extension
# File lib/image_optim/image_path.rb, line 30 def temp_path(*args, &block) ext = extname self.class.temp_file_path([basename(ext).to_s, ext], *args, &block) end