Class: VagrantPlugins::DataBags::Action::PersistDataBags

Inherits:
Base
  • Object
show all
Defined in:
lib/vagrant-databags/action/persist_databags.rb

Instance Method Summary collapse

Methods inherited from Base

#chef_provisioner_type, #machine_chef_provisioners

Constructor Details

#initialize(app, env) ⇒ PersistDataBags

Returns a new instance of PersistDataBags.



9
10
11
12
13
14
# File 'lib/vagrant-databags/action/persist_databags.rb', line 9

def initialize(app, env)
  @app = app

  klass = self.class.name.downcase.split('::').last
  @logger = Log4r::Logger.new("vagrant::databags::#{klass}")
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-databags/action/persist_databags.rb', line 16

def call(env)
  chef_provisioners = machine_chef_provisioners(env[:machine])

  chef_provisioners.each do |chef|
    if env[:machine].config.databags.map.size > 0
      env[:ui].detail "[vagrant-databags] Persisting temp data bags"
      provisioner_type = chef_provisioner_type(chef)
      DataBagsContainer.instance.persist_machine_data_bags(env[:machine], provisioner_type)
    end
  end

  @app.call(env)
end

#recover(env) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/vagrant-databags/action/persist_databags.rb', line 30

def recover(env)
  chef_provisioners = machine_chef_provisioners(env[:machine])
  chef_provisioners.each do |chef|
    provisioner_type = chef_provisioner_type(chef)
    env[:ui].info "Cleaning up temporal data bags"
    DataBagsContainer.instance.clean(env[:machine], provisioner_type)
  end
end