Class: Vagrant::Action::Builtin::ProvisionerCleanup
- Inherits:
-
Object
- Object
- Vagrant::Action::Builtin::ProvisionerCleanup
- Includes:
- MixinProvisioners
- Defined in:
- lib/vagrant/action/builtin/provisioner_cleanup.rb
Overview
This action will run the cleanup methods on provisioners and should be used as part of any Destroy action.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #do_cleanup(env) ⇒ Object
-
#initialize(app, env, place = nil) ⇒ ProvisionerCleanup
constructor
A new instance of ProvisionerCleanup.
Methods included from MixinProvisioners
Constructor Details
#initialize(app, env, place = nil) ⇒ ProvisionerCleanup
Returns a new instance of ProvisionerCleanup.
13 14 15 16 17 18 19 |
# File 'lib/vagrant/action/builtin/provisioner_cleanup.rb', line 13 def initialize(app, env, place=nil) @app = app @logger = Log4r::Logger.new("vagrant::action::builtin::provision_cleanup") place ||= :after @place = place.to_sym end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/vagrant/action/builtin/provisioner_cleanup.rb', line 21 def call(env) do_cleanup(env) if @place == :before # Continue, we need the VM to be booted. @app.call(env) do_cleanup(env) if @place == :after end |
#do_cleanup(env) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vagrant/action/builtin/provisioner_cleanup.rb', line 30 def do_cleanup(env) type_map = provisioner_type_map(env) # Ask the provisioners to modify the configuration if needed provisioner_instances(env).each do |p, _| name = type_map[p].to_s # Check if the subclass defined a cleanup method. The parent # provisioning class defines a `cleanup` method, so we cannot use # `respond_to?` here. Instead, we have to check if _this_ instance # defines a cleanup task. if p.public_methods(false).include?(:cleanup) env[:ui].info(I18n.t("vagrant.provisioner_cleanup", name: name, )) p.cleanup else @logger.debug("Skipping cleanup tasks for `#{name}' - not defined") end end end |