Class: Caterer::Action::Berkshelf::Clean

Inherits:
Caterer::Action::Base show all
Defined in:
lib/caterer/action/berkshelf/clean.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Clean

Returns a new instance of Clean.



8
9
10
11
# File 'lib/caterer/action/berkshelf/clean.rb', line 8

def initialize(app, env)
  super
  @shelf = Caterer::Berkshelf.shelf_for(env)
end

Instance Attribute Details

#shelfObject (readonly)

Returns the value of attribute shelf.



6
7
8
# File 'lib/caterer/action/berkshelf/clean.rb', line 6

def shelf
  @shelf
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/caterer/action/berkshelf/clean.rb', line 13

def call(env)

  config = env[:config]
  image  = config.images[env[:image]]

  if image
    image.provisioners.each do |provisioner|
      if provisioner.is_a? Caterer::Provisioner::ChefSolo or env[:force_berks_clean]
        ::Berkshelf.formatter.msg "cleaning Caterer's shelf"
        FileUtils.remove_dir(shelf, fore: true)
      end
    end
  end

  @app.call(env)
end