Method: Utilities::PuppetModule#validate_module_dir

Defined in:
lib/retrospec/plugins/v1/plugin/puppet_module.rb

#validate_module_dir(dir) ⇒ Object

processes a directory and expands to its full path, assumes ‘./’ returns the validated dir



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/retrospec/plugins/v1/plugin/puppet_module.rb', line 65

def validate_module_dir(dir)
  # first check to see if manifests directory even exists when path is nil
  if dir.nil?
    dir = '.'
  elsif dir.instance_of?(Array)
    puts 'Retrospec - an array of module paths is not supported at this time'.fatal
    raise Retrospec::Puppet::InvalidModulePathError
  end
  dir = File.expand_path(dir)
  manifest_dir = File.join(dir, 'manifests')
  if !File.exist?(manifest_dir)
    puts "No manifest directory in #{manifest_dir}, cannot validate this is a module".fatal
    raise Retrospec::Puppet::NoManifestDirError
  else
    files = Dir.glob("#{manifest_dir}/**/*.pp")
    warn "No puppet manifest files found at #{manifest_dir}".warning if files.length < 1
    # validate the manifest files, because if one files doesn't work it affects everything
    files.each do |file|
      begin
        parser.parse_file(file)
      rescue Puppet::ParseError
        puts "Manifest file: #{file} has parser errors, please fix and re-check using\n puppet parser validate #{file}".fatal
        raise Retrospec::Puppet::ParserError
      rescue SystemExit => e
        puts "Manifest file: #{file} has parser errors, please fix and re-check using\n puppet parser validate #{file}".fatal
        raise Retrospec::Puppet::ParserError
      end
    end
  end
  dir
end