Sha256: bddc4ecc7e8d02dc266d5b0b9ba6743b8de8fa1d4aa9df2e36ba3cddea9298b9

Contents?: true

Size: 853 Bytes

Versions: 1

Compression:

Stored size: 853 Bytes

Contents

class TemplateInvocation < ActiveRecord::Base
  include ForemanTasks::Concerns::ActionSubject

  belongs_to :template, :class_name => 'JobTemplate', :foreign_key => 'template_id'
  belongs_to :job_invocation, :inverse_of => :template_invocations
  has_many :input_values, :class_name => 'TemplateInvocationInputValue', :dependent => :destroy
  has_one :targeting, :through => :job_invocation

  validates_associated :input_values
  validate :provides_required_input_values

  def to_action_input
    { :id => id, :name => template.name }
  end

  private

  def provides_required_input_values
    required_input_ids = self.template.template_inputs.where(:required => true).pluck(:id)
    unless (required_input_ids - self.input_values.map(&:template_input_id)).empty?
      errors.add(:base, _("Not all required inputs have values."))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_remote_execution-0.0.7 app/models/template_invocation.rb