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.


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

def initialize(params = {})
  @container_params = params.to_h.with_indifferent_access[:container].reject do |k, _v|
    IGNORE_ATTRIBUTES.include?(k)
  end
  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


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

def aker_job_id
  @aker_job_id
end

#modelObject (readonly)

Returns the value of attribute model


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

def model
  @model
end

Class Method Details

.create(params) ⇒ Object


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

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

Instance Method Details

#as_json(_options = {}) ⇒ Object


48
49
50
51
52
# File 'app/aker/factories/job.rb', line 48

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

#createObject

Persists a Job and all associated materials.


41
42
43
44
45
46
# File 'app/aker/factories/job.rb', line 41

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


35
36
37
# File 'app/aker/factories/job.rb', line 35

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

#studyObject


54
55
56
57
58
59
60
61
# File 'app/aker/factories/job.rb', line 54

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