Class: VagrantPlugins::LibrarianChef::Action::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-librarian-chef/action/librarian_chef.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Install

Returns a new instance of Install.



8
9
10
11
12
# File 'lib/vagrant-librarian-chef/action/librarian_chef.rb', line 8

def initialize(app, env)
  @app = app
  # Config#finalize! SHOULD be called automatically
  env[:machine].config.librarian_chef.finalize!
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-librarian-chef/action/librarian_chef.rb', line 14

def call(env)
  config = env[:machine].config.librarian_chef

  project_path = get_project_path(env, config)
  if project_path
    env[:ui].info "Installing Chef cookbooks with Librarian-Chef..."
    environment = Librarian::Chef::Environment.new({
      :project_path => project_path
    })
    Librarian::Action::Ensure.new(environment).run
    Librarian::Action::Resolve.new(environment).run
    Librarian::Action::Install.new(environment).run
  else
    env[:ui].info "Couldn't find Cheffile at #{config.cheffile_path}."
  end
  @app.call(env)
end

#get_project_path(env, config) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/vagrant-librarian-chef/action/librarian_chef.rb', line 32

def get_project_path(env, config)
  # look for a Cheffile in the configured cheffile_dir
  if FileTest.exist? File.join(env[:root_path], config.cheffile_path)
    return File.join(env[:root_path], config.cheffile_dir)
  elsif FileTest.exist? File.expand_path(config.cheffile_path)
    return File.expand_path(config.cheffile_dir)
  end
end