Sha256: e97f0afb461450f9ea57b22c90a0085c771c41c9d6238a52e583dbef614d73d4

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

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

  include ForemanRemoteExecution::ErrorsFlattener
  FLATTENED_ERRORS_MAPPING = { :input_values => lambda do |input_value|
                                                 _("Input") + " #{input_value.template_input.name}"
                                                end }


  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_inputs = self.template.template_inputs.where(:required => true)
    missing_inputs = required_inputs.reject { |input| self.input_values.map(&:template_input_id).include?(input.id) }
    unless missing_inputs.empty?
      errors.add(:base, _("Not all required inputs have values. Missing inputs: %s") % missing_inputs.map(&:name).join(', '))
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman_remote_execution-0.1.1 app/models/template_invocation.rb
foreman_remote_execution-0.1.0 app/models/template_invocation.rb
foreman_remote_execution-0.0.10 app/models/template_invocation.rb
foreman_remote_execution-0.0.8 app/models/template_invocation.rb