Sha256: 73f417afd3afe85154e82c9f828c2e75efb8e8ab8cbae860ac14019d60cdf01c

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

class RemoteExecutionFeature < ActiveRecord::Base
  attr_accessible :label, :name, :provided_input_names, :description, :job_template_id

  validates :label, :name, :presence => true, :uniqueness => true

  belongs_to :job_template

  extend FriendlyId
  friendly_id :label

  def provided_input_names
    self.provided_inputs.to_s.split(',').map(&:strip)
  end

  def provided_input_names=(values)
    self.provided_inputs = Array(values).join(',')
  end

  def self.feature(label)
    self.find_by_label(label) || raise(::Foreman::Exception.new(N_('Unknown remote execution feature %s'), label))
  end

  def self.register(label, name, options = {})
    return false unless RemoteExecutionFeature.table_exists?
    options.assert_valid_keys(:provided_inputs, :description)
    feature = self.find_by_label(label)
    if feature.nil?
      feature = self.create!(:label => label, :name => name, :provided_input_names => options[:provided_inputs], :description => options[:description])
    else
      feature.update_attributes!(:name => name, :provided_input_names => options[:provided_inputs], :description => options[:description])
    end
    return feature
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_remote_execution-1.0.0 app/models/remote_execution_feature.rb
foreman_remote_execution-0.3.2 app/models/remote_execution_feature.rb