Class: Kitchen::Provisioner::Chef::Librarian

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/kitchen/provisioner/chef/librarian.rb

Overview

Chef cookbook resolver that uses Librarian-Chef and a Cheffile to calculate # dependencies.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cheffile, path, logger = Kitchen.logger) ⇒ Librarian

Returns a new instance of Librarian.



37
38
39
40
41
# File 'lib/kitchen/provisioner/chef/librarian.rb', line 37

def initialize(cheffile, path, logger = Kitchen.logger)
  @cheffile   = cheffile
  @path       = path
  @logger     = logger
end

Instance Attribute Details

#cheffileObject (readonly)

Returns the value of attribute cheffile.



59
60
61
# File 'lib/kitchen/provisioner/chef/librarian.rb', line 59

def cheffile
  @cheffile
end

#loggerObject (readonly)

Returns the value of attribute logger.



59
60
61
# File 'lib/kitchen/provisioner/chef/librarian.rb', line 59

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



59
60
61
# File 'lib/kitchen/provisioner/chef/librarian.rb', line 59

def path
  @path
end

Class Method Details

.load!(logger = Kitchen.logger) ⇒ Object



43
44
45
# File 'lib/kitchen/provisioner/chef/librarian.rb', line 43

def self.load!(logger = Kitchen.logger)
  load_librarian!(logger)
end

.load_librarian!(logger) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kitchen/provisioner/chef/librarian.rb', line 61

def self.load_librarian!(logger)
  first_load = require 'librarian/chef/environment'
  require 'librarian/action/resolve'
  require 'librarian/action/install'

  version = ::Librarian::Chef::VERSION
  if first_load
    logger.debug("Librarian-Chef #{version} library loaded")
  else
    logger.debug("Librarian-Chef #{version} previously loaded")
  end
rescue LoadError => e
  logger.fatal("The `librarian-chef' gem is missing and must be installed" +
    " or cannot be properly activated. Run" +
    " `gem install librarian-chef` or add the following to your" +
    " Gemfile if you are using Bundler: `gem 'librarian-chef'`.")
  raise UserError,
    "Could not load or activate Librarian-Chef (#{e.message})"
end

Instance Method Details

#resolveObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/kitchen/provisioner/chef/librarian.rb', line 47

def resolve
  version = ::Librarian::Chef::VERSION
  info("Resolving cookbook dependencies with Librarian-Chef #{version}...")
  debug("Using Cheffile from #{cheffile}")

  env = ::Librarian::Chef::Environment.new(
    :project_path => File.dirname(cheffile))
  env.config_db.local["path"] = path
  ::Librarian::Action::Resolve.new(env).run
  ::Librarian::Action::Install.new(env).run
end