Sha256: c1acbd3d2472d1aaa760e5a7404f62ffafee187edbf1e4f29b3491d852cad17a

Contents?: true

Size: 676 Bytes

Versions: 9

Compression:

Stored size: 676 Bytes

Contents

require 'image_optim/image_path'

class ImageOptim
  class Handler
    attr_reader :result
    def initialize(original)
      raise ArgumentError, 'original should respond to temp_path' unless original.respond_to?(:temp_path)

      @original = original
      @result = nil
    end

    def process
      @src ||= @original
      @dst ||= @original.temp_path

      if yield @src, @dst
        @result = @dst
        if @src == @original
          @src, @dst = @dst, nil
        else
          @src, @dst = @dst, @src
        end
      end
    end

    # Remove extra temp files
    def cleanup
      if @dst
        @dst.unlink
        @dst = nil
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
image_optim-0.13.3 lib/image_optim/handler.rb
image_optim-0.13.2 lib/image_optim/handler.rb
image_optim-0.13.1 lib/image_optim/handler.rb
image_optim-0.13.0 lib/image_optim/handler.rb
image_optim-0.12.1 lib/image_optim/handler.rb
image_optim-0.12.0 lib/image_optim/handler.rb
image_optim-0.11.2 lib/image_optim/handler.rb
image_optim-0.11.1 lib/image_optim/handler.rb
image_optim-0.11.0 lib/image_optim/handler.rb