lib/templates.rake in foreman_templates-1.5.0 vs lib/templates.rake in foreman_templates-2.0.0

- old
+ new

@@ -30,11 +30,11 @@ # Get template type unless kind = TemplateKind.find_by_name(@metadata['kind']) raise NoKindError end - db_template = ConfigTemplate.find_or_initialize_by_name(@name) + db_template = ProvisioningTemplate.find_or_initialize_by_name(@name) data = { :template => @text, :snippet => false, :template_kind_id => kind.id } @@ -89,11 +89,11 @@ end { :diff => diff, :status => status, :result => result } end def update_snippet - db_snippet = ConfigTemplate.find_or_initialize_by_name(@name) + db_snippet = ProvisioningTemplate.find_or_initialize_by_name(@name) data = { :template => @text, :snippet => true } string = db_snippet.new_record? ? "Created" : "Updated" @@ -141,12 +141,12 @@ dirname = ENV['dirname'] ? ENV['dirname'] : '/' filter = ENV['filter'] ? ENV['filter'] : nil repo = ENV['repo'] ? ENV['repo'] : "https://github.com/theforeman/community-templates.git" # Check out the community templates to a temp location + dir = Dir.mktmpdir begin - dir = Dir.mktmpdir gitrepo = Git.clone(repo, dir) branch = ENV['branch'] ? ENV['branch'] : get_default_branch(gitrepo) gitrepo.checkout(branch) if branch # Build a list of ERB files to parse @@ -157,11 +157,11 @@ @metadata = metadata(@text) # Get the name and filter filename = template.split('/').last title = filename.split('.').first - @name = @metadata ['name'] || title + @name = @metadata['name'] || title @name = [prefix, @name].compact.join() next if filter and not @name.match(/#{filter}/i) unless @metadata['kind'] puts " Error: Must specify template kind" @@ -189,10 +189,10 @@ puts " Error: Unknown template type '#{@metadata['kind']}'" next end end ensure - FileUtils.remove_entry_secure(dir) + FileUtils.remove_entry_secure(dir) if File.exist?(dir) end end end