Class: Chef::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-berksfile-env.rb

Instance Method Summary collapse

Instance Method Details

#load_berksfile(path = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chef-berksfile-env.rb', line 20

def load_berksfile(path=nil)
  raise "You must define the environment name before doing load_berksfile" if path.nil? && name.empty?
  
  berksfile_path = path.nil? ? "environments/#{name}/Berksfile" : path
  Chef::Log.debug("Using Berksfile path [#{berksfile_path}]")

  begin
    berksfile = ::Berkshelf::Berksfile.new find_berksfile(berksfile_path)

    berksfile.list.each do |dependency|
      cookbook dependency.name, "= #{dependency.locked_version.to_s}"
    end
  rescue ::Berkshelf::LockfileNotFound => e
    raise "Your Berkshelf file [#{path}] has not been locked. Run 'berks install' to lock it"
  end

end

#load_berksfile_lock(path = nil) ⇒ Object

Parameters:

  • path (defaults to: nil)

    path to lock file

Raises:

  • Berkshelf::LockfileNotFound exception



11
12
13
14
15
16
17
18
# File 'lib/chef-berksfile-env.rb', line 11

def load_berksfile_lock(path=nil)
  lockfile = ::Berkshelf::Lockfile.from_file(path)
  raise ::Berkshelf::LockfileNotFound, "Berks lock file is not present: #{path}" unless lockfile.present?

  lockfile.locks.each_pair do |_, dependency|
    cookbook dependency.name, "= #{dependency.locked_version.to_s}"
  end
end