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.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/pdk/generate/puppet_object.rb', line 259 def with_templates require 'pdk/logger' require 'pdk/module/templatedir' 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::Module::TemplateDir.new(PDK::Util::TemplateURI.new(template[:uri])) do |template_dir| template_paths = template_dir.object_template_for(object_type) if template_paths config_hash = template_dir.object_config yield template_paths, config_hash # 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: object_type, url: template[:uri] }) else raise PDK::CLI::FatalError, _('Unable to find the %{type} template in %{url}.') % { type: object_type, url: template[:uri] } end end end rescue ArgumentError => e raise PDK::CLI::ExitWithError, e end |