Class: Puppet::Parser::TypeLoader
- Includes:
- Node::Environment::Helper
- Defined in:
- lib/puppet/parser/type_loader.rb
Defined Under Namespace
Classes: Helper
Instance Method Summary collapse
-
#import(pattern, dir) ⇒ Object
private
Import manifest files that match a given file glob pattern.
-
#import_all ⇒ Object
private
Load all of the manifest files in all known modules.
-
#initialize(env) ⇒ TypeLoader
constructor
A new instance of TypeLoader.
- #known_resource_types ⇒ Object
- #parse_file(file) ⇒ Object
-
#try_load_fqname(type, fqname) ⇒ Object
Try to load the object with the given fully qualified name.
Methods included from Node::Environment::Helper
Constructor Details
#initialize(env) ⇒ TypeLoader
Returns a new instance of TypeLoader.
120 121 122 123 |
# File 'lib/puppet/parser/type_loader.rb', line 120 def initialize(env) self.environment = env @loading_helper = Helper.new end |
Instance Method Details
#import(pattern, dir) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Import manifest files that match a given file glob pattern.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/puppet/parser/type_loader.rb', line 69 def import(pattern, dir) return if Puppet[:ignoreimport] modname, files = Puppet::Parser::Files.find_manifests_in_modules(pattern, environment) if files.empty? abspat = File.(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 |
#import_all ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load all of the manifest files in all known modules.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/puppet/parser/type_loader.rb', line 90 def import_all module_names = [] # Collect the list of all known modules environment.modulepath.each do |path| Dir.chdir(path) do Dir.glob("*").each do |dir| next unless FileTest.directory?(dir) module_names << dir end end end module_names.uniq! # 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. module_names.each do |name| mod = Puppet::Module.new(name, :environment => environment) Find.find(File.join(mod.path, "manifests")) do |path| if path =~ /\.pp$/ or path =~ /\.rb$/ load_files(mod.name, [path]) end end end end |
#known_resource_types ⇒ Object
116 117 118 |
# File 'lib/puppet/parser/type_loader.rb', line 116 def known_resource_types environment.known_resource_types end |
#parse_file(file) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/puppet/parser/type_loader.rb', line 145 def parse_file(file) Puppet.debug("importing '#{file}' in environment #{environment}") parser = Puppet::Parser::Parser.new(environment) parser.file = file return parser.parse end |
#try_load_fqname(type, fqname) ⇒ Object
Try to load the object with the given fully qualified name.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/puppet/parser/type_loader.rb', line 126 def try_load_fqname(type, fqname) return nil if fqname == "" # special-case main. name2files(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 # We couldn't load the item # I'm not convienced we should just drop these errors, but this # preserves existing behaviours. end end # Nothing found. return nil end |