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.


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

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

Instance Attribute Details

#containerObject

Returns the value of attribute container.


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

def container
  @container
end

#sampleObject (readonly)

Returns the value of attribute sample.


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

def sample
  @sample
end

#studyObject

Returns the value of attribute study.


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

def study
  @study
end

Instance Method Details

#as_jsonObject


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

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

#createObject

Persists the material including the associated container


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

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


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

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


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

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