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_in_module(reference, environment) ⇒ Object private
-
.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.
-
.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 /).
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.
39 40 41 42 43 |
# File 'lib/puppet/parser/files.rb', line 39 def find_file(file, environment) find_in_module(file, environment) do |mod,module_file| mod.file(module_file) end end |
.find_in_module(reference, 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.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/puppet/parser/files.rb', line 67 def find_in_module(reference, environment) if Puppet::Util.absolute_path?(reference) reference else path, file = split_file_path(reference) mod = environment.module(path) if file && mod yield(mod, 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.
14 15 16 17 18 19 20 21 22 |
# File 'lib/puppet/parser/files.rb', line 14 def find_manifests_in_modules(pattern, environment) module_name, file_pattern = split_file_path(pattern) if mod = environment.module(module_name) [mod.name, mod.match_manifests(file_pattern)] else [nil, []] end 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 couple of ways:
* absolute path: the path is simply 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.
60 61 62 63 64 |
# File 'lib/puppet/parser/files.rb', line 60 def find_template(template, environment) find_in_module(template, environment) do |mod,template_file| mod.template(template_file) 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 /).
85 86 87 88 89 90 91 |
# File 'lib/puppet/parser/files.rb', line 85 def split_file_path(path) if path == "" || Puppet::Util.absolute_path?(path) nil else path.split(File::SEPARATOR, 2) end end |