Class: R10K::Puppetfile
- Inherits:
-
Object
- Object
- R10K::Puppetfile
- Includes:
- Logging, Util::Purgeable
- Defined in:
- lib/r10k/puppetfile.rb
Defined Under Namespace
Classes: DSL
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#basedir ⇒ Object
readonly
Returns the value of attribute basedir.
-
#forge ⇒ Object
readonly
Returns the value of attribute forge.
-
#moduledir ⇒ Object
readonly
Returns the value of attribute moduledir.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#puppetfile_path ⇒ Object
readonly
Returns the value of attribute puppetfile_path.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #add_module(name, args) ⇒ Object
-
#desired_contents ⇒ Array<String>
List all modules that should exist in the module directory.
-
#initialize(basedir, moduledir = nil, puppetfile = nil) ⇒ Puppetfile
constructor
A new instance of Puppetfile.
- #load ⇒ Object
- #load! ⇒ Object
- #managed_directory ⇒ Object
- #set_forge(forge) ⇒ Object
- #set_moduledir(moduledir) ⇒ Object
Methods included from Util::Purgeable
#current_contents, #logger, #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.
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 = 'forge.puppetlabs.com' end |
Instance Attribute Details
#basedir ⇒ Object (readonly)
Returns the value of attribute basedir.
22 23 24 |
# File 'lib/r10k/puppetfile.rb', line 22 def basedir @basedir end |
#forge ⇒ Object (readonly)
Returns the value of attribute forge.
14 15 16 |
# File 'lib/r10k/puppetfile.rb', line 14 def forge @forge end |
#moduledir ⇒ Object (readonly)
Returns the value of attribute moduledir.
26 27 28 |
# File 'lib/r10k/puppetfile.rb', line 26 def moduledir @moduledir end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
18 19 20 |
# File 'lib/r10k/puppetfile.rb', line 18 def modules @modules end |
#puppetfile_path ⇒ Object (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
74 75 76 |
# File 'lib/r10k/puppetfile.rb', line 74 def add_module(name, args) @modules << R10K::Module.new(name, @moduledir, args) end |
#desired_contents ⇒ Array<String>
This implements a required method for the Purgeable mixin
List all modules that should exist in the module directory
87 88 89 |
# File 'lib/r10k/puppetfile.rb', line 87 def desired_contents @modules.map { |mod| mod.name } end |
#load ⇒ Object
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_directory ⇒ Object
80 81 82 |
# File 'lib/r10k/puppetfile.rb', line 80 def managed_directory @moduledir end |
#set_forge(forge) ⇒ Object
59 60 61 |
# File 'lib/r10k/puppetfile.rb', line 59 def set_forge(forge) @forge = forge end |
#set_moduledir(moduledir) ⇒ Object
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 |