Method: PDK::Generate::PuppetObject#with_templates
- Defined in:
- lib/pdk/generate/puppet_object.rb
#with_templates {|template_paths, config_hash| ... } ⇒ 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.
Search the possible template directories in order of preference to find a template that can be used to render a new object of the specified type.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/pdk/generate/puppet_object.rb', line 157 def with_templates require 'pdk/logger' require 'pdk/util/template_uri' templates.each do |template| if template[:uri].nil? PDK.logger.debug('No %{dir_type} template found; trying next template directory.' % { dir_type: template[:type] }) next end PDK::Template.with(PDK::Util::TemplateURI.new(template[:uri]), context) do |template_dir| if template_files.any? { |source_file, _| template_dir.has_single_item?(source_file) } yield template_dir # TODO: refactor to a search-and-execute form instead return # work is done # rubocop:disable Lint/NonLocalExitFromIterator elsif template[:allow_fallback] PDK.logger.debug('Unable to find a %{type} template in %{url}; trying next template directory.' % { type: friendly_name, url: template[:uri] }) else raise PDK::CLI::FatalError, 'Unable to find the %{type} template in %{url}.' % { type: friendly_name, url: template[:uri] } end end end rescue ArgumentError => e raise PDK::CLI::ExitWithError, e end |