Class: Aker::Factories::Material

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

Overview

An Aker material which in this case is a Samples. Must have a Container Must have minimal data which relates to SampleMetadata and includes:

* name (Aker uuid)
* gender

Optional data:

* donor_id
* phenotype
* sample_common_name (Aker: common name)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, container, study) ⇒ Material

Returns a new instance of Material


22
23
24
25
26
# File 'app/aker/factories/material.rb', line 22

def initialize(params, container, study)
  @params = params
  @container = container
  @study = study
end

Instance Attribute Details

#containerObject

Returns the value of attribute container


15
16
17
# File 'app/aker/factories/material.rb', line 15

def container
  @container
end

#sampleObject (readonly)

Returns the value of attribute sample


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

def sample
  @sample
end

#studyObject

Returns the value of attribute study


15
16
17
# File 'app/aker/factories/material.rb', line 15

def study
  @study
end

Instance Method Details

#as_jsonObject


55
56
57
# File 'app/aker/factories/material.rb', line 55

def as_json
  Aker::Material.new(sample).attributes
end

#createObject

Persists the material including the associated container


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/aker/factories/material.rb', line 36

def create
  return unless valid?

  container_model = container.create
  @sample = Sample.include_uuid.find_by(uuids: { external_id: @params[:_id] })
  create_sample! unless @sample

  container_model.put_sample_in_container(sample, study)
  put_study_in_sample(study)

  Aker::Material.new(@sample).update!(@params)

  @sample
end

#create_sample!Object


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

def create_sample!
  sanger_sample_id = SangerSampleId.generate_sanger_sample_id!(study.abbreviation)
  @sample = Sample.create!(name: sanger_sample_id, sanger_sample_id: sanger_sample_id)
  @sample.create_uuid_object!(external_id: @params[:_id])
end

#put_study_in_sample(study) ⇒ Object


51
52
53
# File 'app/aker/factories/material.rb', line 51

def put_study_in_sample(study)
  sample.studies << study if study && !sample.studies.include?(study)
end