Class: Dockerspec::Builder::ImageGC
- Inherits:
-
Object
- Object
- Dockerspec::Builder::ImageGC
- Includes:
- Singleton
- Defined in:
- lib/dockerspec/builder/image_gc.rb
Overview
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.
Instance Method Summary collapse
-
#add(image) ⇒ Object
Adds a Docker image to be garbage deleted at the end.
-
#finalize ⇒ Object
Removes all the Docker images.
-
#initialize ⇒ ImageGC
constructor
The Image Garbage Collector constructor.
Constructor Details
#initialize ⇒ ImageGC
The Image Garbage Collector constructor.
38 39 40 41 |
# File 'lib/dockerspec/builder/image_gc.rb', line 38 def initialize @images = [] ObjectSpace.define_finalizer(self, proc { finalize }) end |
Instance Method Details
#add(image) ⇒ Object
Adds a Docker image to be garbage deleted at the end.
52 53 54 |
# File 'lib/dockerspec/builder/image_gc.rb', line 52 def add(image) @images << image end |
#finalize ⇒ Object
Removes all the Docker images.
Automatically called at the end of the RSpec/Ruby run.
65 66 67 68 |
# File 'lib/dockerspec/builder/image_gc.rb', line 65 def finalize @images.each { |i| ::Docker::Image.remove(i, force: true) } @images = [] end |