Class: R10K::Puppetfile

Inherits:
Object
  • Object
show all
Includes:
Logging, Util::Purgeable
Defined in:
lib/r10k/puppetfile.rb

Defined Under Namespace

Classes: DSL

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Purgeable

#current_contents, #pending_contents, #purge!, #stale_contents

Methods included from Logging

formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level

Constructor Details

#initialize(basedir, moduledir = nil, puppetfile = nil) ⇒ Puppetfile

Returns a new instance of Puppetfile.

Parameters:

  • basedir (String)
  • puppetfile (String) (defaults to: nil)

    The path to the Puppetfile, default to ##basedir/Puppetfile



33
34
35
36
37
38
39
40
# File 'lib/r10k/puppetfile.rb', line 33

def initialize(basedir, moduledir = nil, puppetfile = nil)
  @basedir         = basedir
  @moduledir       = moduledir  || File.join(basedir, 'modules')
  @puppetfile_path = puppetfile || File.join(basedir, 'Puppetfile')

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

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



21
22
23
# File 'lib/r10k/puppetfile.rb', line 21

def basedir
  @basedir
end

#forgeObject (readonly)

Returns the value of attribute forge.



13
14
15
# File 'lib/r10k/puppetfile.rb', line 13

def forge
  @forge
end

#moduledirObject (readonly)

Returns the value of attribute moduledir.



25
26
27
# File 'lib/r10k/puppetfile.rb', line 25

def moduledir
  @moduledir
end

#modulesObject (readonly)

Returns the value of attribute modules.



17
18
19
# File 'lib/r10k/puppetfile.rb', line 17

def modules
  @modules
end

#puppetfile_pathObject (readonly)

Returns the value of attribute puppetfile_path.



29
30
31
# File 'lib/r10k/puppetfile.rb', line 29

def puppetfile_path
  @puppetfile_path
end

Instance Method Details

#add_module(name, args) ⇒ Object

Parameters:

  • name (String)
  • args (*Object)


67
68
69
# File 'lib/r10k/puppetfile.rb', line 67

def add_module(name, args)
  @modules << R10K::Module.new(name, @moduledir, args)
end

#desired_contentsArray<String>

Note:

This implements a required method for the Purgeable mixin

List all modules that should exist in the module directory

Returns:

  • (Array<String>)


80
81
82
# File 'lib/r10k/puppetfile.rb', line 80

def desired_contents
  @modules.map { |mod| mod.name }
end

#loadObject



42
43
44
45
46
47
48
# File 'lib/r10k/puppetfile.rb', line 42

def load
  if File.readable? @puppetfile_path
    self.load!
  else
    logger.debug "Puppetfile #{@puppetfile_path.inspect} missing or unreadable"
  end
end

#load!Object



50
51
52
53
# File 'lib/r10k/puppetfile.rb', line 50

def load!
  dsl = R10K::Puppetfile::DSL.new(self)
  dsl.instance_eval(puppetfile_contents, @puppetfile_path)
end

#managed_directoryObject



73
74
75
# File 'lib/r10k/puppetfile.rb', line 73

def managed_directory
  @moduledir
end

#set_forge(forge) ⇒ Object

Parameters:

  • forge (String)


56
57
58
# File 'lib/r10k/puppetfile.rb', line 56

def set_forge(forge)
  @forge = forge
end

#set_moduledir(moduledir) ⇒ Object

Parameters:

  • moduledir (String)


61
62
63
# File 'lib/r10k/puppetfile.rb', line 61

def set_moduledir(moduledir)
  @moduledir = moduledir
end