Sha256: 29f97b220251e496f9659a20182e79b41e242bc331c4f8edbf2fab869d40e7fa

Contents?: true

Size: 715 Bytes

Versions: 9

Compression:

Stored size: 715 Bytes

Contents

require 'fspath'
require 'image_size'

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)
      end
    end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
image_optim-0.6.0 lib/image_optim/image_path.rb
image_optim-0.5.1 lib/image_optim/image_path.rb
image_optim-0.5.0 lib/image_optim/image_path.rb
image_optim-0.4.2 lib/image_optim/image_path.rb
image_optim-0.4.1 lib/image_optim/image_path.rb
image_optim-0.4.0 lib/image_optim/image_path.rb
image_optim-0.3.2 lib/image_optim/image_path.rb
image_optim-0.3.1 lib/image_optim/image_path.rb
image_optim-0.3.0 lib/image_optim/image_path.rb