lib/pdk/control_repo.rb in pdk-1.16.0 vs lib/pdk/control_repo.rb in pdk-1.17.0
- old
+ new
@@ -2,10 +2,20 @@
module PDK
module ControlRepo
CONTROL_REPO_FILES = %w[environment.conf Puppetfile].freeze
+ DEFAULT_IGNORED = [
+ '/pkg/',
+ '~*',
+ '/coverage',
+ # Strictly speaking this isn't default but if people have tricked older PDK into thinking that a
+ # Control Repo is a module, they may have recursive symlinks in spec/fixtures/modules
+ '/spec/fixtures/modules/',
+ '/vendor/',
+ ].freeze
+
# Returns path to the root of the Control Repo being worked on.
#
# An environment.conf is required for a PDK compatible Control Repo,
# whereas Puppetfile is optional.
#
@@ -44,7 +54,37 @@
# false otherwise.
def control_repo_root?(path = Dir.pwd)
CONTROL_REPO_FILES.any? { |file| PDK::Util::Filesystem.file?(File.join(path, file)) }
end
module_function :control_repo_root?
+
+ # Returns a PDK::Config::Namespace for the specified environment.conf file.
+ # Note there is no validation of the path.
+ #
+ # @param path [String] The path to the environment.conf file
+ #
+ # @return [PDK::Config::IniFile] The configuration file
+ def environment_conf_as_config(path)
+ PDK::Config::IniFile.new('environment', file: path) do
+ setting :modulepath do
+ # As per https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
+ default_to { 'modules:$basemodulepath' }
+ end
+
+ setting :manifest do
+ # As per https://puppet.com/docs/puppet/latest/config_file_environment.html#allowed-settings
+ default_to { 'manifests/' }
+ end
+ end
+ end
+ module_function :environment_conf_as_config
+
+ def default_ignored_pathspec(ignore_dotfiles = true)
+ require 'pathspec'
+
+ PathSpec.new(DEFAULT_IGNORED).tap do |ps|
+ ps.add('.*') if ignore_dotfiles
+ end
+ end
+ module_function :default_ignored_pathspec
end
end