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.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/pdk/generate/puppet_object.rb', line 206 def with_templates templates.each do |template| if template[:url].nil? PDK.logger.debug(_('No %{dir_type} template specified; trying next template directory.') % { dir_type: template[:type] }) next end PDK::Module::TemplateDir.new(template[:url]) 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[:url] }) else raise PDK::CLI::FatalError, _('Unable to find the %{type} template in %{url}.') % { type: object_type, url: template[:url] } end end end rescue ArgumentError => e raise PDK::CLI::ExitWithError, e end |