Sha256: e7846b7b9fb397f5ad80452489cb20a21199820d1cf96e4c4b7c83b57fe894f2

Contents?: true

Size: 1.16 KB

Versions: 15

Compression:

Stored size: 1.16 KB

Contents

# This class is a shim to handle the importing of templates via the
# foreman_templates plugin. It expects a method like
#     def import(name, text, metadata)
# but REx already has an import! method, so this class provides the
# translation layer.

class JobTemplateImporter
  def self.import!(name, text, metadata, force = false)
    skip = skip_locked(name, force)
    return skip if skip

    template = JobTemplate.import_parsed(name, text, metadata, :update => true, :force => force)
    c_or_u = template.new_record? ? 'Created' : 'Updated'

    result = "  #{c_or_u} Template #{id_string template}:#{name}"
    { :old => template.template_was,
      :new => template.template,
      :status => template.save,
      :result => result}
  end

  def self.skip_locked(name, force)
    template = JobTemplate.find_by :name => name

    if template && template.locked? && !template.new_record? && !force
      { :old => template.template_was,
        :new => template.template,
        :status => false,
        :result => "Skipping Template #{id_string template}:#{name} - template is locked" }
    end
  end

  def self.id_string(template)
    template ? template.id.to_s : ''
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
foreman_remote_execution-1.5.1 app/models/job_template_importer.rb
foreman_remote_execution-1.5.0 app/models/job_template_importer.rb
foreman_remote_execution-1.4.6 app/models/job_template_importer.rb
foreman_remote_execution-1.4.5 app/models/job_template_importer.rb
foreman_remote_execution-1.4.4 app/models/job_template_importer.rb
foreman_remote_execution-1.4.3 app/models/job_template_importer.rb
foreman_remote_execution-1.4.2 app/models/job_template_importer.rb
foreman_remote_execution-1.3.7 app/models/job_template_importer.rb
foreman_remote_execution-1.3.6 app/models/job_template_importer.rb
foreman_remote_execution-1.4.1 app/models/job_template_importer.rb
foreman_remote_execution-1.3.5 app/models/job_template_importer.rb
foreman_remote_execution-1.3.4 app/models/job_template_importer.rb
foreman_remote_execution-1.3.3 app/models/job_template_importer.rb
foreman_remote_execution-1.3.2 app/models/job_template_importer.rb
foreman_remote_execution-1.3.1 app/models/job_template_importer.rb