Skip to content

Commit

Permalink
remove intermediate file used in handler
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Feb 5, 2014
1 parent ba0ea57 commit 7ebc2db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/image_optim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def optimize_image(original)
worker.optimize(src, dst)
end
end
handler.cleanup
if handler.result
ImagePath::Optimized.new(handler.result, original)
end
Expand Down
8 changes: 8 additions & 0 deletions lib/image_optim/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@ def process
end
end
end

# Remove extra temp files
def cleanup
if @dst
@dst.unlink
@dst = nil
end
end
end
end
4 changes: 4 additions & 0 deletions spec/image_optim/handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@
[src, dst].should == [temp_a, temp_b]; true
end
handler.result.should == temp_b

temp_a.should_receive(:unlink).once
handler.cleanup
handler.cleanup
end
end

0 comments on commit 7ebc2db

Please sign in to comment.