Module: PuppetExamplesHelpers

Defined in:
lib/puppet-examples-helpers.rb,
lib/puppet-examples-helpers/version.rb

Overview

A main module of puppet-examples-helpers

Constant Summary collapse

DEFAULT_MODULENAME =
'modulename'.freeze
BASE_EXAMPLES_PATH =
Pathname.new('examples')
DEFAULT_INIT_FILENAME =
'init'.freeze
VERSION =
'0.1.0'.freeze

Instance Method Summary collapse

Instance Method Details

#example(classname = nil) ⇒ String

Reads an example mainifests from examples/ directory This can be useful in puppet’s acceptance tests

Parameters:

  • classname (String) (defaults to: nil)

    The file path to be read, in puppet loader convention

Returns:

  • (String)

    The example file contents



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puppet-examples-helpers.rb', line 13

def example(classname = nil)
  paths = normalize(classname).split('::')[1..-1]
  paths = [DEFAULT_INIT_FILENAME] if paths.empty?
  paths[-1] = "#{paths[-1]}.pp"

  path = BASE_EXAMPLES_PATH
  paths.each do |subpath|
    path = path.join(subpath)
  end
  raise "Can't read example manifest '#{path}'" unless path.readable?
  $stderr.puts "Reading example manifest '#{path}'"
  path.read
end