module Puppet::Parser::Files

Public Instance Methods

find_file(file, environment) click to toggle source

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.

@param template [String] the file selector @param environment [Puppet::Node::Environment] the environment in which to search @return [String, nil] the absolute path to the file or nil if there is no file found

@api private

   # File lib/puppet/parser/files.rb
40 def find_file(file, environment)
41   find_in_module(file, environment) do |mod,module_file|
42     mod.file(module_file)
43   end
44 end
find_in_module(reference, environment) { |mod, file| ... } click to toggle source

@api private

   # File lib/puppet/parser/files.rb
68 def find_in_module(reference, environment)
69   if Puppet::Util.absolute_path?(reference)
70     reference
71   else
72     path, file = split_file_path(reference)
73     mod = environment.module(path)
74 
75     if file && mod
76       yield(mod, file)
77     else
78       nil
79     end
80   end
81 end
find_manifests_in_modules(pattern, environment) click to toggle source

Return a list of manifests as absolute filenames matching the given pattern.

@param pattern [String] A reference for a file in a module. It is the

format "<modulename>/<file glob>"

@param environment [Puppet::Node::Environment] the environment of modules

@return [Array(String, Array<String>)] the module name and the list of files found @api private

   # File lib/puppet/parser/files.rb
14 def find_manifests_in_modules(pattern, environment)
15   module_name, file_pattern = split_file_path(pattern)
16 
17   mod = environment.module(module_name)
18   if mod
19     [mod.name, mod.match_manifests(file_pattern)]
20   else
21     [nil, []]
22   end
23 end
find_template(template, environment) click to toggle source

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.

@param template [String] the template selector @param environment [Puppet::Node::Environment] the environment in which to search @return [String, nil] the absolute path to the template file or nil if there is no file found

@api private

   # File lib/puppet/parser/files.rb
61 def find_template(template, environment)
62   find_in_module(template, environment) do |mod,template_file|
63     mod.template(template_file)
64   end
65 end
split_file_path(path) click to toggle source

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 /). @api private

   # File lib/puppet/parser/files.rb
86 def split_file_path(path)
87   if path == "" || Puppet::Util.absolute_path?(path)
88     nil
89   else
90     path.split(File::SEPARATOR, 2)
91   end
92 end