class Teneo::DataModel::ConversionWorkflow
noinspection RailsParamDefResolve
Public Class Methods
from_hash(hash, id_tags = [:representation_id, :name])
click to toggle source
Calls superclass method
Teneo::DataModel::Base::from_hash
# File lib/teneo/data_model/conversion_workflow.rb, line 29 def self.from_hash(hash, id_tags = [:representation_id, :name]) representation_label = hash.delete(:representation) query = representation_label ? {label: representation_label} : {id: hash[:representation_id]} representation = record_finder Teneo::DataModel::Representation, query hash[:representation_id] = representation.id conversion_tasks = hash.delete(:tasks) item = super(hash, id_tags) do |item, h| item.position = (position = h.delete(:position)) ? position : item.position = item.representation.conversion_workflows.count end if conversion_tasks item.conversion_tasks.clear conversion_tasks.each_with_index do |conversion_task, index| item.conversion_tasks << Teneo::DataModel::ConversionTask.from_hash(conversion_task.merge(conversion_workflow_id: item.id, position: index + 1)) end item.save! end item end
Public Instance Methods
init_position()
click to toggle source
# File lib/teneo/data_model/conversion_workflow.rb, line 23 def init_position # noinspection RubyResolve self.position ||= self.class.where(representation_id: representation_id).pluck(:position).max + 1 end