class R10K::Puppetfile

Attributes

basedir[R]

@!attribute [r] basedir

@return [String] The base directory that contains the Puppetfile
forge[R]

@!attribute [r] forge

@return [String] The URL to use for the Puppet Forge
moduledir[R]

@!attribute [r] moduledir

@return [String] The directory to install the modules #{basedir}/modules
modules[R]

@!attribute [r] modules

@return [Array<R10K::Module>]
puppetfile_path[R]

@!attrbute [r] #puppetfile_path

@return [String] The path to the Puppetfile

Public Class Methods

new(basedir, moduledir = nil, puppetfile = nil) click to toggle source

@param [String] basedir @param [String] puppetfile The path to the Puppetfile, default to #{basedir}/Puppetfile

# File lib/r10k/puppetfile.rb, line 34
def initialize(basedir, moduledir = nil, puppetfile = nil)
  @basedir         = basedir
  @moduledir       = moduledir  || File.join(basedir, 'modules')
  @puppetfile_path = puppetfile || File.join(basedir, 'Puppetfile')

  @modules = []
  @forge   = 'forgeapi.puppetlabs.com'
end

Public Instance Methods

accept(visitor) click to toggle source
# File lib/r10k/puppetfile.rb, line 91
def accept(visitor)
  visitor.visit(:puppetfile, self) do
    modules.each do |mod|
      mod.accept(visitor)
    end
  end
end
add_module(name, args) click to toggle source

@param [String] name @param [*Object] args

# File lib/r10k/puppetfile.rb, line 74
def add_module(name, args)
  @modules << R10K::Module.new(name, @moduledir, args)
end
desired_contents() click to toggle source

List all modules that should exist in the module directory @note This implements a required method for the Purgeable mixin @return [Array<String>]

# File lib/r10k/puppetfile.rb, line 87
def desired_contents
  @modules.map { |mod| mod.name }
end
load() click to toggle source
# File lib/r10k/puppetfile.rb, line 43
def load
  if File.readable? @puppetfile_path
    self.load!
  else
    logger.debug "Puppetfile #{@puppetfile_path.inspect} missing or unreadable"
  end
end
load!() click to toggle source
# File lib/r10k/puppetfile.rb, line 51
def load!
  dsl = R10K::Puppetfile::DSL.new(self)
  dsl.instance_eval(puppetfile_contents, @puppetfile_path)
rescue SyntaxError, LoadError, ArgumentError => e
  raise R10K::Error.wrap(e, "Failed to evaluate #{@puppetfile_path}")
end
managed_directory() click to toggle source
# File lib/r10k/puppetfile.rb, line 80
def managed_directory
  @moduledir
end
set_forge(forge) click to toggle source

@param [String] forge

# File lib/r10k/puppetfile.rb, line 59
def set_forge(forge)
  @forge = forge
end
set_moduledir(moduledir) click to toggle source

@param [String] moduledir

# File lib/r10k/puppetfile.rb, line 64
def set_moduledir(moduledir)
  @moduledir = if Pathname.new(moduledir).absolute?
    moduledir
  else
    File.join(basedir, moduledir)
  end
end

Private Instance Methods

puppetfile_contents() click to toggle source
# File lib/r10k/puppetfile.rb, line 101
def puppetfile_contents
  File.read(@puppetfile_path)
end