Module: Puppet::Parser::Files
- Defined in:
- lib/puppet/parser/files.rb
Class Method Summary collapse
-
.find_file(file, environment) ⇒ String?
private
Find the path to the given file selector.
-
.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) ⇒ String?
private
Find the path to the given template selector.
- .find_template_in_module(template, environment) ⇒ Object private
-
.find_template_in_templatepath(template, environment) ⇒ Object
private
Templatepaths are deprecated functionality, this will be going away in Puppet 4.
-
.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_file(file, environment) ⇒ 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.
Find the path to the given file selector. Files can be selected in one of two ways:
* absolute path: the path is simply returned
* modulename/filename selector: a file is found in the file directory
of the named module.
In the second case a nil is returned if there isn’t a file found. In the first case (absolute path), there is no existence check done and so the path will be returned even if there isn’t a file available.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet/parser/files.rb', line 43 def find_file(file, environment) if Puppet::Util.absolute_path?(file) file else path, module_file = split_file_path(file) mod = environment.module(path) if module_file && mod mod.file(module_file) else nil end end end |
.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) ⇒ 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.
Find the path to the given template selector. Templates can be selected in a number of ways:
* absolute path: the path is simply returned
* path relative to the templatepath setting: a file is found and the path
is returned
* modulename/filename selector: a file is found in the template directory
of the named module.
In the last two cases a nil is returned if there isn’t a file found. In the first case (absolute path), there is no existence check done and so the path will be returned even if there isn’t a file available.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/puppet/parser/files.rb', line 75 def find_template(template, environment) if Puppet::Util.absolute_path?(template) template else in_templatepath = find_template_in_templatepath(template, environment) if in_templatepath in_templatepath else find_template_in_module(template, environment) end end 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.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/puppet/parser/files.rb', line 106 def find_template_in_module(template, environment) path, file = split_file_path(template) mod = environment.module(path) if file && mod mod.template(file) else nil end end |
.find_template_in_templatepath(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.
Templatepaths are deprecated functionality, this will be going away in Puppet 4.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/puppet/parser/files.rb', line 92 def find_template_in_templatepath(template, environment) template_paths = templatepath(environment) if template_paths template_paths.collect do |path| File::join(path, template) end.find do |f| Puppet::FileSystem.exist?(f) end else nil end 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 /).
130 131 132 133 134 135 136 |
# File 'lib/puppet/parser/files.rb', line 130 def split_file_path(path) if path == "" || 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.
120 121 122 123 124 125 |
# File 'lib/puppet/parser/files.rb', line 120 def templatepath(environment) dirs = Puppet.settings.value(:templatedir, environment.to_s).split(File::PATH_SEPARATOR) dirs.select do |p| File::directory?(p) end end |