Module: Puppet::Parser::Files
- Defined in:
- lib/puppet/parser/files.rb
Class Method Summary collapse
-
.find_manifests_in_modules(pattern, environment) ⇒ Array(String, Array<String>)
private
Return a list of manifests as absolute filenames matching the given pattern.
-
.find_template(template, environment) ⇒ Object
private
Find the concrete file denoted by
file. - .find_template_in_module(template, environment) ⇒ Object private
-
.split_file_path(path) ⇒ Object
private
Split the path into the module and the rest of the path, or return nil if the path is empty or absolute (starts with a /).
-
.templatepath(environment) ⇒ Object
private
Return an array of paths by splitting the
templatedirconfig parameter.
Class Method Details
.find_manifests_in_modules(pattern, environment) ⇒ Array(String, Array<String>)
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.
Return a list of manifests as absolute filenames matching the given pattern.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/puppet/parser/files.rb', line 15 def find_manifests_in_modules(pattern, environment) module_name, file_pattern = split_file_path(pattern) begin if mod = environment.module(module_name) return [mod.name, mod.match_manifests(file_pattern)] end rescue Puppet::Module::InvalidName # one of the modules being loaded might have an invalid name and so # looking for one might blow up since we load them lazily. end [nil, []] end |
.find_template(template, environment) ⇒ 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.
Find the concrete file denoted by file. If file is absolute, return it directly. Otherwise try to find relative to the templatedir config param. If that fails try to find it as a template in a module. In all cases, an absolute path is returned, which does not necessarily refer to an existing file
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet/parser/files.rb', line 36 def find_template(template, environment) if template == File.(template) return template end if template_paths = templatepath(environment) # If we can find the template in :templatedir, we return that. template_paths.collect { |path| File::join(path, template) }.each do |f| return f if Puppet::FileSystem.exist?(f) end end # check in the default template dir, if there is one if td_file = find_template_in_module(template, environment) return td_file end nil end |
.find_template_in_module(template, environment) ⇒ 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.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/parser/files.rb', line 59 def find_template_in_module(template, environment) path, file = split_file_path(template) # Because templates don't have an assumed template name, like manifests do, # we treat templates with no name as being templates in the main template # directory. return nil unless file if mod = environment.module(path) and t = mod.template(file) return t end nil end |
.split_file_path(path) ⇒ 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.
Split the path into the module and the rest of the path, or return nil if the path is empty or absolute (starts with a /).
86 87 88 89 90 91 92 |
# File 'lib/puppet/parser/files.rb', line 86 def split_file_path(path) if path == "" or Puppet::Util.absolute_path?(path) nil else path.split(File::SEPARATOR, 2) end end |
.templatepath(environment) ⇒ 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.
Return an array of paths by splitting the templatedir config parameter.
76 77 78 79 80 81 |
# File 'lib/puppet/parser/files.rb', line 76 def templatepath(environment) dirs = Puppet.settings.value(:templatedir, environment.to_s).split(File::PATH_SEPARATOR) dirs.select do |p| File::directory?(p) end end |