class PuppetfileFixturesGenerator::Puppetfile

Manipulate Puppetfiles so they can be converted to fixtures or diffed

Public Class Methods

new(puppetfile_path) click to toggle source

Constructor @param puppetfile_path Path to the Puppetfile

# File lib/puppetfile_fixtures_generator/puppetfile.rb, line 10
def initialize(puppetfile_path)
  @pf_path = puppetfile_path
end

Public Instance Methods

modules_hash() click to toggle source

@return [Hash] Modules from the Puppetfile

# File lib/puppetfile_fixtures_generator/puppetfile.rb, line 15
def modules_hash
  @modules_hash ||=
    begin
      hash = {}
      puppetfile.modules.each { |mod| module_builder(mod, hash) }
      hash
    end
end

Private Instance Methods

add_category(key, hash) click to toggle source

@param key [String] The key to add to the hash @param hsh [Hash] The hash to add the key to @return [Hash] Hash with added key

# File lib/puppetfile_fixtures_generator/puppetfile.rb, line 74
def add_category(key, hash)
  hash[key] = {} unless
    hash.key?(key)
end
add_module(category, name, repo, version, hsh) click to toggle source

@param category [String] The hash key to add the module to @param name [String] The name of the module @param repo [String] The repo for the module @param version [String] The version of the module @param hsh [Hash] The hash to add the module to @return [Hash] Passed in hash with module added

# File lib/puppetfile_fixtures_generator/puppetfile.rb, line 66
def add_module(category, name, repo, version, hsh)
  hash = { name => { 'repo' => repo, 'ref' => version } }
  hsh[category].merge!(hash)
end
module_builder(mod, hash) click to toggle source

Deconstruct a module to its parts. Add the deconstructed module to the appropiate key in a hash. If the appropiate key does not exist in the hash add the key to the hash.

@param hash [Hash] Hash to add the module to @param mod [R10K::Module] @return [Hash] Passed in hash with the module added

# File lib/puppetfile_fixtures_generator/puppetfile.rb, line 44
def module_builder(mod, hash) # rubocop:disable Metrics/MethodLength
  case mod.properties[:type]
  when :forge
    ctgry   = 'forge_modules'
    repo    = mod.title
    version = mod.expected_version
  when :git
    ctgry   = 'repositories'
    repo    = mod.instance_variable_get :@remote
    version = mod.instance_variable_get :@ref
  end

  add_category(ctgry, hash)
  add_module(ctgry, mod.name, repo, version, hash)
end
puppetfile(puppetfile_path = @pf_path) click to toggle source

@param puppetfile_path Path to the Puppetfile @return [R10K::Puppetfile]

# File lib/puppetfile_fixtures_generator/puppetfile.rb, line 28
def puppetfile(puppetfile_path = @pf_path)
  @puppetfile ||=
    begin
      pf = R10K::Puppetfile.new(Pathname.new(puppetfile_path).dirname.to_s)
      pf.load
      pf
    end
end