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, #logger, #pending_contents, #purge!, #stale_contents

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, 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



34
35
36
37
38
39
40
41
# 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

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



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

def basedir
  @basedir
end

#forgeObject (readonly)

Returns the value of attribute forge.



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

def forge
  @forge
end

#moduledirObject (readonly)

Returns the value of attribute moduledir.



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

def moduledir
  @moduledir
end

#modulesObject (readonly)

Returns the value of attribute modules.



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

def modules
  @modules
end

#puppetfile_pathObject (readonly)

Returns the value of attribute puppetfile_path.



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

def puppetfile_path
  @puppetfile_path
end

Instance Method Details

#accept(visitor) ⇒ Object



91
92
93
94
95
96
97
# 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) ⇒ Object

Parameters:

  • name (String)
  • args (*Object)


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

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>)


87
88
89
# File 'lib/r10k/puppetfile.rb', line 87

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

#loadObject



43
44
45
46
47
48
49
# 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!Object



51
52
53
54
55
56
# 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 => e
  raise R10K::Error.wrap(e, "Failed to evaluate #{@puppetfile_path}")
end

#managed_directoryObject



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

def managed_directory
  @moduledir
end

#set_forge(forge) ⇒ Object

Parameters:

  • forge (String)


59
60
61
# File 'lib/r10k/puppetfile.rb', line 59

def set_forge(forge)
  @forge = forge
end

#set_moduledir(moduledir) ⇒ Object

Parameters:

  • moduledir (String)


64
65
66
67
68
69
70
# 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