Class: SampleManifestExcel::Upload::Processor::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, SequencescapeExcel::SubclassChecker
Defined in:
app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb

Overview

Uploads will be processed slightly differently based on the manifest type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(upload) ⇒ Base

Returns a new instance of Base.


20
21
22
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 20

def initialize(upload)
  @upload = upload
end

Instance Attribute Details

#uploadObject (readonly)

Returns the value of attribute upload


14
15
16
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 14

def upload
  @upload
end

Instance Method Details

#aliquots_updated?Boolean

Returns:

  • (Boolean)

71
72
73
74
75
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 71

def aliquots_updated?
  downstream_aliquots_updated? ||
    no_substitutions? ||
    log_error_and_return_false('Could not update tags in other assets.')
end

#downstream_aliquots_updated?Boolean

Returns:

  • (Boolean)

67
68
69
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 67

def downstream_aliquots_updated?
  @downstream_aliquots_updated
end

#processed?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 45

def processed?
  samples_updated? && sample_manifest_updated? && aliquots_updated?
end

#run(tag_group) ⇒ Object

If the processor is valid the samples and manifest are updated.


26
27
28
29
30
31
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 26

def run(tag_group)
  return unless valid?

  update_samples_and_aliquots(tag_group)
  update_sample_manifest
end

#sample_manifest_updated?Boolean

Returns:

  • (Boolean)

55
56
57
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 55

def sample_manifest_updated?
  @sample_manifest_updated
end

#samples_updated?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 41

def samples_updated?
  upload.rows.all?(&:sample_skipped_or_updated?) || log_error_and_return_false('Could not update samples')
end

#substitutionsObject


63
64
65
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 63

def substitutions
  @substitutions ||= []
end

#typeObject


59
60
61
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 59

def type
  self.class.to_s
end

#update_sample_manifestObject

Override the sample manifest with the raw uploaded data.


51
52
53
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 51

def update_sample_manifest
  @sample_manifest_updated = upload.sample_manifest.update(uploaded: upload.file)
end

#update_samples_and_aliquots(tag_group) ⇒ Object


33
34
35
36
37
38
39
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 33

def update_samples_and_aliquots(tag_group)
  upload.rows.each do |row|
    row.update_sample(tag_group, upload.override)
    substitutions << row.aliquot.substitution_hash if row.reuploaded?
  end
  update_downstream_aliquots unless no_substitutions?
end