class Dockerspec::Builder::ImageGC
A class to manage docker image deletion. The class stores the images created by {Dockerspec::Builder} objects and deletes them at the end of the Ruby/RSpec run.
Public Class Methods
new()
click to toggle source
The Image Garbage Collector constructor.
@api public
# File lib/dockerspec/builder/image_gc.rb, line 38 def initialize @images = [] ObjectSpace.define_finalizer(self, proc { finalize }) end
Public Instance Methods
add(image)
click to toggle source
Adds a Docker image to be garbage deleted at the end.
@param image [String] Docker image ID.
@return void
@api public
# File lib/dockerspec/builder/image_gc.rb, line 52 def add(image) @images << image end
finalize()
click to toggle source
Removes all the Docker images.
Automatically called at the end of the RSpec/Ruby run.
@return void
@api public
# File lib/dockerspec/builder/image_gc.rb, line 65 def finalize @images.each { |i| ::Docker::Image.remove(i, force: true) } @images = [] end