Sha256: 814ab1bf19fa9b5eabfdbf3e5ad63050bf9b2b94c00bba8fc97f9f84f946677d

Contents?: true

Size: 743 Bytes

Versions: 2

Compression:

Stored size: 743 Bytes

Contents

require 'fspath'
require 'image_size'

require 'image_optim'

class ImageOptim
  class ImagePath < FSPath
    # Get temp path for this file with same extension
    def temp_path(*args, &block)
      ext = extname
      self.class.temp_file_path([basename(ext), ext], *args, &block)
    end

    # Copy file to dest preserving attributes
    def copy(dst)
      FileUtils.copy_file(self, dst, true)
    end

    # Atomic replace src with self
    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)
      end
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
image_optim-0.9.1 lib/image_optim/image_path.rb
image_optim-0.9.0 lib/image_optim/image_path.rb