class Teneo::DataModel::StageTask

noinspection RailsParamDefResolve

Public Class Methods

from_hash(hash, id_tags = [:stage_workflow_id, :position]) click to toggle source
Calls superclass method Teneo::DataModel::Base::from_hash
# File lib/teneo/data_model/stage_task.rb, line 28
def self.from_hash(hash, id_tags = [:stage_workflow_id, :position])
  params = hash.delete(:values)
  item = super(hash, id_tags) do |item, h|
    item.position = (position = h.delete(:position)) ? position : item.stage_workflow.stage_tasks.count
    if (task = h.delete(:task))
      item.task = record_finder Teneo::DataModel::Task, name: task
    end
  end
  if params
    item.parameter_values.clear
    params.each do |name, value|
      item.parameter_values <<
          Teneo::DataModel::ParameterValue.from_hash(name: name, value: value,
                                                     with_values_id: item.id,
                                                     with_values_type: item.class.name)
    end
    item.save!
  end
  item
end

Public Instance Methods

init_position() click to toggle source
# File lib/teneo/data_model/stage_task.rb, line 23
def init_position
  # noinspection RubyResolve
  self.position ||= self.class.where(stage_workflow_id: stage_workflow_id).pluck(:position).max + 1
end