# File lib/puppet/parser/type_loader.rb, line 52 def environment @environment end
# File lib/puppet/parser/type_loader.rb, line 56 def environment=(env) if env.is_a?(String) or env.is_a?(Symbol) @environment = Puppet.lookup(:environments).get!(env) else @environment = env end end
Import manifest files that match a given file glob pattern.
@param pattern [String] the file glob to apply when determining which files
to load
@param dir [String] base directory to use when the file is not
found in a module
@api private
# File lib/puppet/parser/type_loader.rb, line 16 def import(pattern, dir) return if Puppet[:ignoreimport] modname, files = Puppet::Parser::Files.find_manifests_in_modules(pattern, environment) if files.empty? abspat = File.expand_path(pattern, dir) file_pattern = abspat + (File.extname(abspat).empty? ? '{.pp,.rb}' : '' ) files = Dir.glob(file_pattern).uniq.reject { |f| FileTest.directory?(f) } modname = nil if files.empty? raise_no_files_found(pattern) end end load_files(modname, files) end
Load all of the manifest files in all known modules. @api private
# File lib/puppet/parser/type_loader.rb, line 37 def import_all # And then load all files from each module, but (relying on system # behavior) only load files from the first module of a given name. E.g., # given first/foo and second/foo, only files from first/foo will be loaded. environment.modules.each do |mod| load_files(mod.name, mod.all_manifests) end end
# File lib/puppet/parser/type_loader.rb, line 83 def parse_file(file) Puppet.debug("importing '#{file}' in environment #{environment}") parser = Puppet::Parser::ParserFactory.parser(environment) parser.file = file return parser.parse end
Try to load the object with the given fully qualified name.
# File lib/puppet/parser/type_loader.rb, line 65 def try_load_fqname(type, fqname) return nil if fqname == "" # special-case main. files_to_try_for(fqname).each do |filename| begin imported_types = import_from_modules(filename) if result = imported_types.find { |t| t.type == type and t.name == fqname } Puppet.debug "Automatically imported #{fqname} from #{filename} into #{environment}" return result end rescue Puppet::ImportError => detail # I'm not convienced we should just drop these errors, but this # preserves existing behaviours. end end # Nothing found. return nil end
# File lib/puppet/parser/type_loader.rb, line 48 def initialize(env) self.environment = env end