Class: Aker::Factories::Job

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/aker/factories/job.rb

Overview

A job consists of an aker_job_id and materials (samples). Validates presence of aker_job_id and ensures that there is at least one material.

Constant Summary collapse

ATTRIBUTES =
%i[job_id job_uuid work_order_id aker_job_url product_name process_name process_uuid modules product_version product_uuid project_uuid project_name cost_code container materials comment desired_date data_release_uuid
priority].freeze
DEFAULT_ATTRIBUTES =
{ data_release_uuid: nil, materials: {} }.freeze
IGNORE_ATTRIBUTES =
%w[container_id num_of_rows num_of_cols].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Job

Returns a new instance of Job


26
27
28
29
30
# File 'app/aker/factories/job.rb', line 26

def initialize(params = {})
  @container_params = params.to_h.with_indifferent_access[:container].reject { |k, _v| IGNORE_ATTRIBUTES.include?(k) }
  super(DEFAULT_ATTRIBUTES.merge(params))
  @aker_job_id = job_id
end

Instance Attribute Details

#aker_job_idObject (readonly)

Returns the value of attribute aker_job_id


16
17
18
# File 'app/aker/factories/job.rb', line 16

def aker_job_id
  @aker_job_id
end

#modelObject (readonly)

Returns the value of attribute model


16
17
18
# File 'app/aker/factories/job.rb', line 16

def model
  @model
end

Class Method Details

.create(params) ⇒ Object


22
23
24
# File 'app/aker/factories/job.rb', line 22

def self.create(params)
  new(params).create
end

Instance Method Details

#as_json(_options = {}) ⇒ Object


44
45
46
47
48
# File 'app/aker/factories/job.rb', line 44

def as_json(_options = {})
  {
    job: json_attributes
  }
end

#createObject

Persists a Job and all associated materials.


38
39
40
41
42
# File 'app/aker/factories/job.rb', line 38

def create
  return unless valid?

  @model = Aker::Job.create(aker_job_id: aker_job_id, job_uuid: job_uuid, samples: materials.map(&:create), aker_job_url: aker_job_url)
end

#materials=(materials) ⇒ Object


32
33
34
# File 'app/aker/factories/job.rb', line 32

def materials=(materials)
  @materials = build_materials(materials)
end

#studyObject


50
51
52
53
54
55
56
57
# File 'app/aker/factories/job.rb', line 50

def study
  return @study if @study

  uuid = Uuid.find_by(external_id: data_release_uuid)
  return nil unless uuid

  @study = Study.find(uuid.resource_id)
end